Percentile rank is frequently defined by the following formula:
Percentile rank = (L/N)*100
L=Number of values in dataset lower than or equal to value of interest N=number of data points
In R, it is common to calculate percentile rank of values in a vector by
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
This is similar to the PERCENTILERANK.EXC function in Excel.
Is there a function built into R to calculate this? Otherwise, how can I do it?
CodePudding user response:
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
