将分位数输出转化为表格

huangapple go评论71阅读模式
英文:

Transform quantiles output into a table

问题

我有这段代码

tapply(index_articles_migpunts$index_articles_ponderats2_migpunts, index_articles_migpunts$Tramspoblacio, quantile, probs=seq(.1,.9, by =.1)) 

它产生了这个输出:

$`1 - 999`
       10%        20%        30%        40%        50%        60%        70%        80% 
 0.0000000  0.8333333  5.0000000  5.0000000  5.8333333  7.8666667 10.0000000 13.3500000 
       90% 
17.1166667 

$`1000 - 4999`
      10%       20%       30%       40%       50%       60%       70%       80%       90% 
 5.833333 10.866667 13.300000 16.333333 17.479167 19.200000 20.687500 23.091667 28.166667 

$`5000 - 9999`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
11.66667 15.08333 19.16667 21.00000 24.00000 27.33333 30.75000 36.29167 56.75000 

$`10000 - 19999`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
14.85000 18.36667 21.25000 24.13333 26.91667 30.83333 34.84167 39.95000 60.90000 

$`20000 - 39999`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
23.22500 27.66667 31.24167 34.43333 37.75000 41.90000 45.46667 50.41667 66.04167 

$`40000 - 79999`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
34.85417 38.54167 41.14583 44.16667 46.58333 51.00000 54.72917 57.95833 75.60417 

$`80000 - 200000`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
39.11667 41.72500 44.36667 47.22500 49.87500 54.76667 56.66667 58.27500 88.57500 

$`Mayor de 200000`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
45.92917 50.25000 52.75000 53.02500 55.64583 56.11667 63.25833 66.32500 95.31667 

如何将这个控制台输出转换为一个包含不同类别名称的数据框或表格?

非常感谢!

英文:

I have this code

tapply(index_articles_migpunts$index_articles_ponderats2_migpunts, index_articles_migpunts$Tramspoblacio, quantile, probs=seq(.1,.9, by =.1)) 

which gives this output:

$`1 - 999`
       10%        20%        30%        40%        50%        60%        70%        80% 
 0.0000000  0.8333333  5.0000000  5.0000000  5.8333333  7.8666667 10.0000000 13.3500000 
       90% 
17.1166667 

$`1000 - 4999`
      10%       20%       30%       40%       50%       60%       70%       80%       90% 
 5.833333 10.866667 13.300000 16.333333 17.479167 19.200000 20.687500 23.091667 28.166667 

$`5000 - 9999`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
11.66667 15.08333 19.16667 21.00000 24.00000 27.33333 30.75000 36.29167 56.75000 

$`10000 - 19999`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
14.85000 18.36667 21.25000 24.13333 26.91667 30.83333 34.84167 39.95000 60.90000 

$`20000 - 39999`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
23.22500 27.66667 31.24167 34.43333 37.75000 41.90000 45.46667 50.41667 66.04167 

$`40000 - 79999`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
34.85417 38.54167 41.14583 44.16667 46.58333 51.00000 54.72917 57.95833 75.60417 

$`80000 - 200000`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
39.11667 41.72500 44.36667 47.22500 49.87500 54.76667 56.66667 58.27500 88.57500 

$`Mayor de 200000`
     10%      20%      30%      40%      50%      60%      70%      80%      90% 
45.92917 50.25000 52.75000 53.02500 55.64583 56.11667 63.25833 66.32500 95.31667 

How can I transform this console output into a data.frame or a table retaining the distinct categories names?

Thank you very much!

答案1

得分: 1

以下翻译代码部分:

res <- tapply(index_articles_migpunts$index_articles_ponderats2_migpunts, index_articles_migpunts$Tramspoblacio, quantile, probs=seq(.1,.9, by =.1))
df <- do.call(rbind, res)
df$intervals <- names(res)
英文:

something along the lines of the below should do the job. Your result is a named list, so bind the entries into rows in a data.frame using rbind and do.call (or use bind_rows(res) from the dplyr package). Afterwards add the intervals using the names in the result list.

res &lt;- tapply(index_articles_migpunts$index_articles_ponderats2_migpunts, index_articles_migpunts$Tramspoblacio, quantile, probs=seq(.1,.9, by =.1))
df &lt;- do.call(rbind, res)
df$intervals &lt;- names(res)

huangapple
  • 本文由 发表于 2023年3月3日 18:06:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75625661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定