# [R] about the function order()

Emmanuel Charpentier charpent at bacbuc.dyndns.org
Tue Nov 27 15:28:41 CET 2001

```According to Thomas Lumley :

>In a sense it's doing the opposite of what you thought.

>The definition of order() is basically that
>   a[order(a)]
>is in increasing order. This works with your example, where the correct
>order is the fourth, second, first, then third element.

>You may have been looking for rank(), which returns the rank of the
>elements
/>R> a <- c(4.1, 3.2, 6.1, 3.1) /
/>R> order(a) /
>[1] 4 2 1 3
/>R> rank(a) /
>[1] 3 2 4 1
>so rank() tells you what order the numbers are in, order() tells you how
>to get them in ascending order.

Hmmm ... meaning that order behaves like the (gradeup) APL function,
right ? (Yes, I'm *that* old ...).

That should imply that, barring possible ties, rank(x) ==
order(order(x)). Right ?

So : why distinc implementations ? Are there efficiency considerations
I'm missing ?

Or am I completely mistaken ?

--
Emmanuel Charpentier

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```