[R] function sort.list()

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Mon May 6 14:36:43 CEST 2002


> Derar R-people
> 
> I have troubles understanding what the function sort.list() is doing. On
> the homepage it says that it returns a permutation which rearranges a
> vector into ascending or descending order (like order() but on a vector
> instead of a sequence).
> 
> > sort.list(c(0, 2, 10, 11, 4))
> [1] 1 2 5 3 4
> 
> which does not make sense to me.
> 
> In fact I am getting the same (non-sensical) result using order()
> 
> order(c(0, 2, 10, 11, 4))
> [1] 1 2 5 3 4

sort.list and order do return the correct order. What you're seeing is
the indicies that will put the list in order. Try this to see

> c(0,2,10,11,4)[sort.list(c(0,2,10,11,4))]
[1]  0  2  4 10 11
> c(0,2,10,11,4)[order(c(0,2,10,11,4))]
[1]  0  2  4 10 11

> 
> Of course
> 
> rank(c(0, 2, 10, 11, 4))
> 1] 1 2 4 5 3
> 
> gives the correct result.

Not "correct result" but "totally different result."

> 
> Am I missing something obvious here ?
> 

We all have those moments?

Regards,
Sundar

-- 

Sundar Dorai-Raj, Ph.D.
Statistical Methods Engineer
PDF Solutions, Inc.
Richardson TX
(972) 889-3085 x216
(214) 392-7619 cell
sundard at pdf.com
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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