An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120621/880622c6/attachment.pl>
ranking a vector in R
6 messages · Jessy, Jorge I Velez, arun +3 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120620/8dc79711/attachment.pl>
Hi,
dat<-c(5,4,3,12,15) rank(-dat)
[1] 3 4 5 2 1
rank(dat)
[1] 3 2 1 4 5 A.K. ----- Original Message ----- From: Jessy <jmahachie at gmail.com> To: r-help at r-project.org Cc: Sent: Wednesday, June 20, 2012 6:24 PM Subject: [R] ranking a vector in R 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. Regards, Jessy ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120620/1f6dc110/attachment.pl>
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.
On 21/06/2012 07:24, Petr Savicky wrote:
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
Or more generally rank(-xtfrm(x)) which works also for non-numeric x.
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