[R] ranking a vector in R

Petr Savicky savicky at cs.cas.cz
Thu Jun 21 08:24:43 CEST 2012


On Thu, Jun 21, 2012 at 12:24:47AM +0200, Jessy wrote:
> Hello,
> 
> 
> May someone help me with how in R I can rank a vector from highest to
> lowest. i.e  rank 1 (smallest rank) is given to the highest value instead
> of the usual way that it get's the highest rank.

Hello:

Try

  x <- c(3, 2, 4, 1)
  rank(-x)

  [1] 2 3 1 4

Hope this helps.

Petr Savicky.



More information about the R-help mailing list