Re: [R] reordering numbers in a vector

2003-11-17 Thread Giovanni Petris

If you need only to sort a vector, then sort() does the job.
To go back to the original vector, the following may work:

> x <- unique(rpois(30,5))
> x
[1] 8 5 3 4 6 9 2 7
> x.sorted <- sort(x)
> x.sorted
[1] 2 3 4 5 6 7 8 9
> x.sorted[order(order(x))]
[1] 8 5 3 4 6 9 2 7


HTH,
Giovanni

> Date: Mon, 17 Nov 2003 15:21:18 -0800 (PST)
> From: Merrill Birkner <[EMAIL PROTECTED]>
> Sender: [EMAIL PROTECTED]
> Precedence: list
> 
> 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-
> 
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
> 

-- 

 __
[  ]
[ Giovanni Petris [EMAIL PROTECTED] ]
[ Department of Mathematical Sciences  ]
[ University of Arkansas - Fayetteville, AR 72701  ]
[ Ph: (479) 575-6324, 575-8630 (fax)   ]
[ http://definetti.uark.edu/~gpetris/  ]
[__]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] reordering numbers in a vector

2003-11-17 Thread Sundar Dorai-Raj


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
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] reordering numbers in a vector

2003-11-17 Thread Merrill Birkner
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-

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help