order {ranking} R Documentation

Ordering Permutation

Description


order returns a permutation which rearranges its first argument
into ascending or descending order, breaking ties by further
arguments. sort.list is the same, using only one argument.

Usage

order(x,
    decreasing = FALSE);

Arguments

x

a sequence of numeric, complex, character or logical vectors, all of the same length, or a classed R object. [as Array]

decreasing

logical. Should the sort order be increasing or decreasing? For the "radix" method, this can be a vector of length equal to the number of arguments in .... For the other methods, it must be length one. [as boolean]

Details

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). The sort used is stable (except for method = "quick"), so any unresolved ties will be left in their original ordering.

Complex values are sorted first by the real part, then the imaginary part.

Except for method "radix", the sort order for character vectors will depend on the collating sequence of the locale in use: see Comparison.

The "shell" method is generally the safest bet and is the default method, except for short factors, numeric vectors, integer vectors and logical vectors, where "radix" is assumed. Method "radix" stably sorts logical, numeric and character vectors in linear time. It outperforms the other methods, although there are caveats (see sort). Method "quick" for sort.list is only supported for numeric x with na.last = NA, is not stable, and is slower than "radix".

partial = NULL is supported for compatibility with other implementations of S, but no other values are accepted and ordering is always complete.

For a classed R object, the sort order is taken from xtfrm: as its help page notes, this can be slow unless a suitable method has been defined or is.numeric(x) is true. For factors, this sorts on the internal codes, which is particularly appropriate for ordered factors.

Authors

SMRUCC genomics Institute

Value

An integer vector unless any of the inputs has 2^31 or more elements, when it is a double vector.

clr value class

Examples


[Package ranking version 2.33.856.6961 Index]