[R] reordering numbers in a vector

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Tue Nov 18 00:26:30 CET 2003



Merrill Birkner wrote:
> Suppose you initially create a vector a<-c(5,1,3,4). 
> You want to sort the vector before performing specific
> calculations to the numbers.  You now have the vector
> [1,3,4,5].  How can you now revert back to your
> initial ordering of [5,1,3,4]? Is there a specific
> command or 'sort by' command that one could use?
> 
> Thanks again-
> 

I think what you want is ?order.

a <- c(5, 1, 3, 4)
a.ord <- a[order(a)]

HTH,
Sundar




More information about the R-help mailing list