Re: [R] R function for percentrank

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Sun, 2 Dec 2007 11:42:36 -0500 (EST)


Ah so ! Thank you .
--- Gabor Grothendieck <ggrothendieck_at_gmail.com> wrote:

> Its a bit tricky if you want to get it to work
> exactly the same as
> Excel even in the presence of runs but in terms of
> the R approx function
> I think percentrank corresponds to ties = "min" if
> the value is among those
> in the table and ties = "ordered" otherwise so:
>
> percentrank <- function(table, x = table) {
> table <- sort(table)
> ties <- ifelse(match(x, table, nomatch = 0),
> "min", "ordered")
> len <- length(table)
> f <- function(x, ties)
> (approx(table, seq(0, len = len), x, ties =
> ties)$y) / (len - 1)
> mapply(f, x, ties)
> }
>
> # test
> tab <- c(1, 1, 2, 2, 3, 3)
> percentrank(tab, 2:6/2) # c(0, .3, .4, .7, .8)
>
> which is the same result as Excel 2007 gives.
>
> On Dec 1, 2007 6:37 AM, 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,
> >
> > --
> > Tom
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
> >
>
> ______________________________________________
> 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.
>



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 Sun 02 Dec 2007 - 16:49:45 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 Sun 02 Dec 2007 - 18: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.