[R] Finding percentile of a value from an empirical distribution

R. Michael Weylandt <michael.weylandt@gmail.com> michael.weylandt at gmail.com
Wed Jan 11 06:05:51 CET 2012


Look at ?ecdf 

Michael

On Jan 10, 2012, at 11:52 PM, "Robert A'gata" <rhelpacc at gmail.com> wrote:

> Hello,
> 
> I am not sure how to do this in R. Any suggestion would be
> appreciated. I have a vector of values from where I build an empirical
> CDF. For example:
> 
>> x <- seq(1,100)
>> x <- sample(x,1000,replace=T)
>> quantile(x,probs=seq(0,1,.05))
>    0%     5%    10%    15%    20%    25%    30%    35%    40%    45%
>  50%    55%
>  1.00   5.00  10.00  16.00  20.00  25.00  31.00  36.00  41.00  45.55
> 50.00  56.00
>   60%    65%    70%    75%    80%    85%    90%    95%   100%
> 60.00  65.00  70.00  74.00  80.00  85.00  91.00  95.05 100.00
> 
> I would like to write a function that takes in a number z and vector x
> (i.e. the raw vector).It returns percentile of z wrt x. E.g.
> 
>> f(71,x)
> 
> Should return something around 0.708 or 0.709. I am wondering if there
> is any pre-packaged functions that do this in R? If not, how can I
> write such a function. Any suggestion would be appreciated.
> 
> Robert
> 
> ______________________________________________
> 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.



More information about the R-help mailing list