[R] Compute rank within factor groups
Greg Snow
Greg.Snow at intermountainmail.org
Thu Jul 12 23:28:25 CEST 2007
Why are you using order instead of rank?
If the data is pre sorted then they tend to give the same result (unless
there are ties), but if your data is not presorted, then the results
will be different.
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
> -----Original Message-----
> From: Ken Williams [mailto:ken.williams at thomson.com]
> Sent: Thursday, July 12, 2007 2:50 PM
> To: Greg Snow; R-help at stat.math.ethz.ch
> Subject: Re: [R] Compute rank within factor groups
>
>
>
>
> On 7/12/07 3:42 PM, "Ken Williams" <ken.williams at thomson.com> wrote:
>
> > I ended up using:
> >
> > wc$rank <- ave( wc$score, wc$report,
> > FUN=function(x) order(x, decreasing=TRUE) )
> >
> > Which gives me the 1-based rank integers I was looking for.
>
> Of course, immediately after sending I realized a simpler way:
>
> wc$rank <- ave( -wc$score, wc$report, FUN=order )
>
> And as a newbie I think I get to be blissfully ignorant of
> which one is faster. =)
>
>
> --
> Ken Williams
> Research Scientist
> The Thomson Corporation
> Eagan, MN
>
>
More information about the R-help
mailing list