# [R] I don't understand the 'order' function

William Dunlap wdunlap at tibco.com
Tue Apr 16 20:35:27 CEST 2013

```I think Duncan said that order and rank were inverses (if there are no ties).  order() has
period 2 so order(order(x)) is also rank(x) if there are no ties.  E.g.,

> data.frame(x, o1=order(x), o2=order(order(x)), o3=order(order(order(x))), o4=order(order(order(order(x)))), rank=rank(x))
x o1 o2 o3 o4 rank
1  2465  8 11  8 11 11.0
2  2255  9 10  9 10 10.0
3  2085 10  9 10  9  9.0
4  1545  7  8  7  8  8.0
5  1335 11  7 11  7  7.0
6  1210  6  6  6  6  6.0
7   920  5  4  5  4  4.0
8   210  4  1  4  1  1.5
9   210  3  2  3  2  1.5
10  505  2  3  2  3  3.0
11 1045  1  5  1  5  5.0

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Julio Sergio
> Sent: Tuesday, April 16, 2013 11:10 AM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] I don't understand the 'order' function
>
> Julio Sergio <juliosergio <at> gmail.com> writes:
>
> >
> > I thought I've understood the 'order' function, using simple examples like:
>
> Thanks to you all!... As Sarah said, what was damaged was my understanding (
> ;-) )... and as Duncan said, I was confusing 'order' with 'rank',
> thanks! Now I understand the 'order' function.
>
>   -Sergio
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help