[R] function sort.list()

Jason Turner jasont at indigoindustrial.co.nz
Mon May 6 13:29:35 CEST 2002


On Mon, May 06, 2002 at 10:50:11AM +0100, Ole Christensen wrote:
> I have troubles understanding what the function sort.list() is doing.
...
> > sort.list(c(0, 2, 10, 11, 4))
> [1] 1 2 5 3 4
...
> order(c(0, 2, 10, 11, 4))
> [1] 1 2 5 3 4
> Am I missing something obvious here ? 

Yup. It's doing exactly what it should.  Try 

zz <- c(0, 2, 10, 11, 4)
zz[order(zz)]

and all will be revealed.  order() returns indices of the 
vector if it were to be shuffled into order.

I thought it was strange at first too, but when combined with
R's other powerful scripting capabilities, it's a truly amazing
workhorse function; don't let its size fool you ;) .

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
64-21-343-545
jasont at indigoindustrial.co.nz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list