

   order {base}                                 R Documentation

   OOrrddeerriinngg PPeerrmmuuttaattiioonn

   DDeessccrriippttiioon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 put
        allowing partial sorting.

   UUssaaggee::

        order(...)
        sort.list(x, partial)

   AArrgguummeennttss::

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

          x: a vector.

    partial: vector of indices for partial sorting.

   DDeettaaiills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 val-
        ues so that permutations returned by `order' move `NA'
        values to the top end of the array.

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

   SSeeee AAllssoo::

        `sort' and `rank'.

   EExxaammppllees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])

