[R] rank in descending order?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Dec 2 09:13:37 CET 2004


On Wed, 1 Dec 2004, Jose Quesada wrote:

> Is there any simple solution to get ranks in descending order?
> Example,
> a <- c(10, 98, 98, 98, 99, 100)
> r <- rank(a, ties.method="average")
>
> produces
> 1 3 3 3 5 6
>
> I would want this instead:
> 6 5 3 3 3 1

What does that correspond to (why are 98 and 99 ranked the same)?  I 
believe you want 6 4 4 4 2 1, which is length(a) + 1 - r, as well as 
rank(-a).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list