order(...)
...
| a sequence of vectors, all of the same length. |
order
returns a permutation which rearranges its first
argument into ascending order, breaking ties by further arguments.
NA
values are treated as greater than any other values
so that permutations returned by
order
move NA
values to the top end of the array.
sort
and rank
.(ii <- order(x <- c(1,1,3:1,1:4,3), y <- c(9,9:1), z <-c(2,1:9))) ## 6 5 2 1 7 4 10 8 3 9 rbind(x,y,z)[,ii] # shows the reordering (ties via 2nd & 3rd arg) ## rearrange matched vectors so that the first is in ascending order x <- c(5:1, 6:8, 12:9) y <- (x - 5)^2 o <- order(x) rbind(x[o], y[o])