[R] rank

ggrothendieck@yifan.net ggrothendieck at yifan.net
Sun Apr 28 23:01:05 CEST 2002


I would like to make a couple of small suggestions regarding
rank.  All of these can be done now but with the the indicated additions,
one could have clearer code:

PRESERVE NAMES
It would be nice if rank(v) preserved the names of vector v.
Currently you have to do this:  rv <- rank(v); names(rv) <- names(v)
which seems unnecessarily elaborate.    Note that when you rank
some items you often want to know which items were ranked 
where so its natural that you would want to preserve the names.

TIED RANKS
It would be nice if there were an option to control whether tied ranks
are averaged or not.  Currently they are averaged.

As a workaround, one can create a function to do this:

myrank <- function(x) {
   y <- order(order(x))
   names(y) <- names(x)
   return(y)
}

but it would be tidier if the option were available within rank itself.

ASCENDING OR DESCENDING
It would be nice if one could specify whether the rank was to be
computed in ascending or descending order.  rank(-x) (in the
case of numeric data) and rank(-rank(x)) with numeric or character
work but an option would be more direct.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list