First off look at what happens with an integer sequence formed from a permutation of 1:10:
> set.seed(123); x <- sample(10)
> x
[1] 3 8 4 7 6 1 10 9 2 5
> order(x)
[1] 6 9 1 3 10 5 4 2 8 7
> order(order(x))
[1] 3 8 4 7 6 1 10 9 2 5
> rank(x)
[1] 3 8 4 7 6 1 10 9 2 5
The order
-operation is its own inverse in this case. And since the order
-operation always returns an sequence starting at 1, then any nested odd applications of order
will be giving the same vector.
Order returns an index vector that can be used to sort the original vector. So the location of the smallest item is in the first position, the location of the second smallest value is next, .... , and the last item is the location of the largest item. So when you then again perform that operation on the index vector, the first item is now the index of the smallest index, and so on .... and that the vector's rank.