Dear all,
I would like to get the order of the values in a vector. I have tried
rank(), order() and searched the archive, though without success.
Here is an example of a try
x= c(20,30,50,40,60,10)
cbind(sort.list(x),x)
x
[1,] 6 20
[2,] 1 30
[3,] 2 50
[4,] 4 40
[5,] 3 60
[6,] 5 10
but I was hoping to get this:
x
[1,] 2 20
[2,] 3 30
[3,] 5 50
[4,] 4 40
[5,] 6 60
[6,] 1 10
I'm most grateful for a tip!
cheers,
Tord
--
Tord Sn?ll
Department of Ecology
Swedish University of Agricultural Sciences (SLU)
P.O. 7002, SE-750 07 Uppsala, Sweden
Office/Mobile/Fax
+46-18-672612/+46-730-891356/+46-18-673537
E-mail: tord.snall at nvb.slu.se
www.nvb.slu.se/staff_tordsnall
On Mon, 19 Mar 2007, Tord Sn?ll wrote:> Dear all, > I would like to get the order of the values in a vector. I have tried > rank(), order() and searched the archive, though without success. > > Here is an example of a try > x= c(20,30,50,40,60,10) > cbind(sort.list(x),x) > x > [1,] 6 20 > [2,] 1 30 > [3,] 2 50 > [4,] 4 40 > [5,] 3 60 > [6,] 5 10 > but I was hoping to get this: > x > [1,] 2 20 > [2,] 3 30 > [3,] 5 50 > [4,] 4 40 > [5,] 6 60 > [6,] 1 10> cbind(rank(x), x)x [1,] 2 20 [2,] 3 30 [3,] 5 50 [4,] 4 40 [5,] 6 60 [6,] 1 10> > I'm most grateful for a tip! > > cheers, > Tord > >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Tord Sn?ll wrote:> Dear all, > I would like to get the order of the values in a vector. I have tried > rank(), order() and searched the archive, though without success. > > Here is an example of a try > x= c(20,30,50,40,60,10) > cbind(sort.list(x),x) > x > [1,] 6 20 > [2,] 1 30 > [3,] 2 50 > [4,] 4 40 > [5,] 3 60 > [6,] 5 10 > but I was hoping to get this: > x > [1,] 2 20 > [2,] 3 30 > [3,] 5 50 > [4,] 4 40 > [5,] 6 60 > [6,] 1 10 > > I'm most grateful for a tip!cbind(rank(x), x) x [1,] 2 20 [2,] 3 30 [3,] 5 50 [4,] 4 40 [5,] 6 60 [6,] 1 10> cheers, > Tord-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
G'day Tord, On Mon, 19 Mar 2007 10:05:47 +0100 Tord Sn?ll <tord.snall at nvb.slu.se> wrote:> but I was hoping to get this: > x > [1,] 2 20 > [2,] 3 30 > [3,] 5 50 > [4,] 4 40 > [5,] 6 60 > [6,] 1 10You did try rank(), didn't you?> x= c(20,30,50,40,60,10) > cbind(rank(x), x)x [1,] 2 20 [2,] 3 30 [3,] 5 50 [4,] 4 40 [5,] 6 60 [6,] 1 10 HTH. Cheers, Berwin
Tord
> x <- c(20,30,50,40,60,10)
> cbind(rank(x),x)
x
[1,] 2 20
[2,] 3 30
[3,] 5 50
[4,] 4 40
[5,] 6 60
[6,] 1 10
>
HTH
rksh
On 19 Mar 2007, at 09:05, Tord Sn?ll wrote:
Dear all,
I would like to get the order of the values in a vector. I have tried
rank(), order() and searched the archive, though without success.
Here is an example of a try
x= c(20,30,50,40,60,10)
cbind(sort.list(x),x)
x
[1,] 6 20
[2,] 1 30
[3,] 2 50
[4,] 4 40
[5,] 3 60
[6,] 5 10
but I was hoping to get this:
x
[1,] 2 20
[2,] 3 30
[3,] 5 50
[4,] 4 40
[5,] 6 60
[6,] 1 10
I'm most grateful for a tip!
cheers,
Tord
>
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
Tord Sn?ll schrieb:> Dear all, > I would like to get the order of the values in a vector. I have tried > rank(), order() and searched the archive, though without success.maybe this page could give you some hints: http://www.ats.ucla.edu/STAT/r/faq/sort.htm Regards Knut