[R] question about order

Waverley waverley.paloalto at gmail.com
Tue Jan 29 02:19:05 CET 2008


I have a data vector as following:
> z
 [1] 183.1370 201.9610 113.7250 140.7840 156.2750  42.1569  42.1569  42.1569
 [9] 240.1960 308.4310  42.1569  42.1569  42.1569  42.1569  42.1569  42.1569
[17]  42.1569  42.1569  42.1569  42.1569 279.8040  42.1569  42.1569

when I sort, it gave me the right order

> sort(z)
 [1]  42.1569  42.1569  42.1569  42.1569  42.1569  42.1569  42.1569  42.1569
 [9]  42.1569  42.1569  42.1569  42.1569  42.1569  42.1569  42.1569 113.7250
[17] 140.7840 156.2750 183.1370 201.9610 240.1960 279.8040 308.4310

BUT when I use the order, the returned index is strange and not right.
 You can check the first 4 values.
> order (z)
 [1]  6  7  8 11 12 13 14 15 16 17 18 19 20 22 23  3  4  5  1  2  9 21 10

I am not sure why R does not order it correctly when handling a vector
with repetitive values.

I use just the first 4 values of z, then it ordered correctly.
> order (z[1:4])
[1] 3 4 1 2

Can someone help?  What is the problem here? Is this a R bug?  How to
order when handling a vector with repetitive values?

-- 
Waverley @ Palo Alto



More information about the R-help mailing list