[R] percentile of a given value: is there a "reverse" quantile function?

peter dalgaard pdalgd at gmail.com
Sat Mar 3 14:33:28 CET 2012


On Mar 3, 2012, at 13:37 , drflxms wrote:

> Dear all,
> 
> I am familiar with obtaining the value corresponding to a chosen
> probability via the quantile function.
> Now I am facing the opposite problem I have a value an want to know it's
> corresponding percentile in the distribution. So is there a function for
> this as well?

For a single value, mean(x <= a) will do. Otherwise check ecdf().

> x <- rnorm(100)
> mean(x <= 2)
[1] 0.97
> ecdf(x)(2)
[1] 0.97
> ecdf(x)(-3:3)
[1] 0.00 0.01 0.14 0.48 0.80 0.97 1.00

if you need values for your original data points, rank(x)/length(x) should do (bar missing value issues).

> 
> Thank you for your support in advance, Felix
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list