[R] question about order

From: Waverley <waverley.paloalto_at_gmail.com>
Date: Mon, 28 Jan 2008 17:19:05 -0800


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

______________________________________________
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.
Received on Tue 29 Jan 2008 - 01:26:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Jan 2008 - 02:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive