Re: [R] R function for percentrank

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Sat, 1 Dec 2007 18:40:14 +0000 (UTC)

David Winsemius <dwinsemius_at_comcast.net> wrote in news:Xns99F989B3A3057dNOTwinscomcast_at_80.91.229.13:

> "tom soyer" <tom.soyer@gmail.com> wrote in
> news:65cc7bdf0712010951p451a993i70da89f285d801de_at_mail.gmail.com:
>

>> John,
>> 
>> The Excel's percentrank function works like this: if one has a number,
>> x for example, and one wants to know the percentile of this number in
>> a given data set, dataset, one would type =percentrank(dataset,x) in
>> Excel to calculate the percentile. So for example, if the data set is
>> c(1:10), and one wants to know the percentile of 2.5 in the data set,
>> then using the percentrank function one would get 0.166, i.e., 2.5 is
>> in the 16.6th percentile. 
>> 
>> I am not sure how to program this function in R. I couldn't find it as
>> a built-in function in R either. It seems to be an obvious choice for
>> a built-in function. I am very surprised, but maybe we both missed it.

>
> My nomination for a function with a similar result would be ecdf(), the
> empirical cumulative distribution function. It is of class "function"
so
> efforts to index ecdf(.)[.] failed for me.
>
>> df4$V2
> [1] 1 1 1 1 1 5 6 7 9 #copied wrong line in R session

Make that;
df4$V2<-c(1,1,3,3,4,5,6,7,10,9)
[1] 1 1 3 3 5 6 7 9

>> ecdf.V2<-ecdf(df4$V2)
>> ecdf.V2(df4$V2)

> [1] 0.2 0.2 0.4 0.4 0.5 0.6 0.7 0.8 1.0 0.9
>
> Don't have Excel, but the OpenOffice.org Calc program has the same
> function. It produces:
> x percentrank(x)
> 1 0.0000000
> 1 0.0000000
> 3 0.2222222
> 3 0.2222222
> 4 0.4444444
> 5 0.5555556
> 6 0.6666667
> 7 0.7777778
> 10 1.0000000
> 9 0.8888889
>
> (Not that I am saying that the OO.o/Excel function is what one _should_
> want. Its behavior seems pathological to me.)
>

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. Received on Sat 01 Dec 2007 - 18:43:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 01 Dec 2007 - 20:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.