Hi, 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 Note that reversing r doesn't work but in small examples. Thanks, -Jose -- jquesada at andrew.cmu.edu Research associate http://lsa.colorado.edu/~quesadaj Dept. of Social and Decision Sciences http://www.andrew.cmu.edu/~jquesada Carnegie Mellon University Porter Hall Phone: 412 268 6011 office PH208-J Fax: 412 268 6938 5000 Forbes ave. 15213, Pittsburgh, PA
Try this: r <- sort(rank(a, ties.method="average"), decreasing=T) Jose Quesada wrote:>Hi, > >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 > >Note that reversing r doesn't work but in small examples. > >Thanks, >-Jose > > >
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 1What 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