[R] function sort.list()

Achim Zeileis zeileis at ci.tuwien.ac.at
Mon May 6 13:07:35 CEST 2002


Ole Christensen wrote:
> 
> 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
> 
> Of course
> 
> rank(c(0, 2, 10, 11, 4))
> 1] 1 2 4 5 3
> 
> gives the correct result.

Both functions give correct results, they just do different things!
rank() gives you the ranks, order() returns what is sometimes also
called anti-ranks. Type
R> c(0, 2, 10, 11, 4)[order(c(0, 2, 10, 11, 4))]
to see what it does. It can be used to rearrange matrices for example.
See help(order) for further examples.
Z

> Am I missing something obvious here ?
> 
> Cheers Ole
> 
> --
> Ole F. Christensen
> Department of Mathematics and Statistics
> Fylde College, Lancaster University
> Lancaster, LA1 4YF, England
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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