order                  package:base                  R Documentation

_O_r_d_e_r_i_n_g _P_e_r_m_u_t_a_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     `order' returns a permutation which rearranges its first argument
     into ascending order, breaking ties by further arguments.
     `sort.list' is the same, using only one argument but allowing
     partial sorting.

_U_s_a_g_e:

     order(..., na.last = TRUE)
     sort.list(x, partial, na.last = TRUE)

_A_r_g_u_m_e_n_t_s:

     ...: a sequence of vectors, all of the same length.

       x: a vector.

 partial: vector of indices for partial sorting.

 na.last: for controlling the treatment of `NA's. If `TRUE', missing
          values in the data are put last; if `FALSE', they are put
          first; if `NA', they are removed. Currently, `TRUE' is the
          only possible value.

_D_e_t_a_i_l_s:

     In the case of ties in the first vector, values in the second are
     used to break the ties.  If the values are still tied, values in
     the later arguments are used to break the tie (see the first
     example).

     `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.  Other options are not (yet) implemented in R.

     `partial' is supplied for compatibility with other implementations
     of S, but the sorting is always complete.

_S_e_e _A_l_s_o:

     `sort' and `rank'.

_E_x_a_m_p_l_e_s:

     (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])

