[R] Getting empirical percentiles for data

Mike Cheung mikewlcheung at hku.hk
Fri Jan 7 06:45:02 CET 2005


Dear List,

I have some discrete data and want to calculate the percentiles and the 
percentile ranks for each of the unique scores. I can calculate the 
percentiles with quantile().

I know that "ecdf" can be used to calculate the empirical cumulative 
distribution. However, I don't know how to exact the cumulative 
probabilities for each unique element. The requirement is similar to the 
"FREQUENCIES" in SPSS. Could someone help me in exacting the cumulative 
probabilities from the ecdf object? Thanks in advance!

# Generating artificial data
x <- round( rnorm(50, mean=50, sd=10) )
probs <- seq(0.1, 0.9, by=0.1)
# Calculating percentiles
x.percentiles <- quantile(x, probs)
# Calculating percentile ranks
x.ranks <- ecdf(x)

Best,
Mike




More information about the R-help mailing list