简体   繁体   English

列值的百分等级-R

[英]Percentile rank of column values - R

I am looking for a percentage rank for each value in a column. 我正在为列中的每个值寻找百分比排名。

It is quite easy in Excel, for example: 在Excel中非常容易,例如:

=RANK.EQ(A1,$A$1:$A$100,1)/COUNT($A$1:$A$100) = RANK.EQ(A1,$ A $ 1:$ A $ 100,1)/ COUNT($ A $ 1:$ A $ 100)

Returns a percent value in a new column that ranks the column I referred to above. 在新列中返回百分比值,该列对我上面提到的列进行排名。

I have no problem finding quantile in R, but have not been able to find anything that accurately gives percentile for every single column value. 我在R中找到分位数没有问题,但是却找不到能够为每个单列值准确给出百分位数的东西。

Try this using the data in your picture: 使用图片中的数据尝试以下操作:

> Cost.Per.Kilo <- c(rep(c(6045170, 5412330, 3719760, 3589220), each=2), 
                     3507400)
> Cost.Per.Kilo
[1] 6045170 6045170 5412330 5412330 3719760 3719760 3589220 3589220 3507400
> CPK.rank <- rank(Cost.Per.Kilo, ties.method="min")
> CPK.rank
[1] 8 8 6 6 4 4 2 2 1
> round(CPK.rank/length(CPK.rank) * 100)
[1] 89 89 67 67 44 44 22 22 11

In your picture you seem to have divided the ranks by 10, but there are only 9 values. 在您的图片中,您似乎已将等级除以10,但是只有9个值。 That is why these percentages do not match. 这就是为什么这些百分比不匹配的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM