[英]Percentile rank (inclusive) in R
Percentile rank is frequently defined by the following formula:百分位等级通常由以下公式定义:
Percentile rank = (L/N)*100百分等级 = (L/N)*100
L=Number of values in dataset lower than or equal to value of interest N=number of data points L=数据集中小于或等于感兴趣值的值的数量 N=数据点的数量
In R, it is common to calculate percentile rank of values in a vector by在 R 中,通常通过以下方式计算向量中值的百分位等级
Percentile_Rank=rank(vec)/length(vec)*100)
However, I would like to use a slightly modified definition of percentile rank, which is defined by the same formula as above but但是,我想使用稍微修改的百分等级定义,它由与上述相同的公式定义,但
L = Number of values in dataset strictly lower than the value of interest L = 数据集中值的数量严格低于感兴趣的值
This is similar to the PERCENTILERANK.EXC function in Excel.这类似于 Excel 中的 PERCENTILERANK.EXC function。
Is there a function built into R to calculate this? R 中是否有内置 function 来计算这个? Otherwise, how can I do it?
否则,我该怎么办?
Is this what you're looking for?这是你要找的吗?
y = 1:10
# traditional percentile
rank(y)/length(y) * 100
# [1] 10 20 30 40 50 60 70 80 90 100
# percentile considering those values preceding current value
vapply(y, function(x){
sum(y < x)/length(y) * 100
}, FUN.VALUE = numeric(1L))
# [1] 0 10 20 30 40 50 60 70 80 90
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.