Re: [R] R function for percentrank

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

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
> 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.)

```--
David Winsemius

>
> On 12/1/07, John Kane <jrkrideau@yahoo.ca> wrote:

>>
>> I don't see one but that means nothing.   I think you
>> can write such a function in a few minutes
>>
>> Will something like this work or am I
>> missunderstanding what Excel's percentrank does ?
>>
>> aa <- rnorm(25);  aa  # data vector
>> percentrank <- function(x) {
>> var  <- sort(x)
>> p.rank <- 1:length(var)/length(var)*100
>> dd  <- cbind(var,p.rank)
>> }
>> pr <- percentrank(aa); pr
>>
>>
>> --- tom soyer <tom.soyer_at_gmail.com> wrote:
>>
>> > Hi,
>> >
>> > Does anyone know if R has a built-in function that
>> > is equvalent to Excel's
>> > percentrank, i.e., returns the rank of a value in a
>> > data set as a percentage
>> > of the data set?
>> >
>> > Thanks,
>> >

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help