Sort into Ascending Numeric or Alphabetic Order

DESCRIPTION:
Returns a vector which is a sorted version of the input. By default, missing values are deleted.

USAGE:
sort(x, partial = NULL, na.last = NA)

REQUIRED ARGUMENTS:
x:
vector, missing values (NAs) are allowed. For numeric vectors infinite values are also allowed.

OPTIONAL ARGUMENTS:
partial:
vector of indices (in ascending order) into data for partial sorting.
na.last:
a length 1 vector. If na.last=NA, missing values are deleted. If na.last=TRUE, missing values are put last; if FALSE, they are put first. An error is given if na.last is of mode "character" and missing values occur in x.

VALUE:
vector with its data sorted into ascending order.

DETAILS:
If partial has positive length, it should contain strictly ascending indices into data, in which case only the elements named in partial will be guaranteed to be in their proper positions after the sort. All other elements will be in their proper gaps between the partial elements, but not necessarily in the proper order within the gaps.

The treatment of missing values is controlled by the na.last argument. The default allows the output to have fewer elements than the input. Any attributes (except names) of x will be lost in the sorting; the result is always a vector.

Infinite values are allowed and are sorted appropriately. Character data are sorted according to the collating sequence, where digits precede upper-case letters, which precede lower-case letters; the position of other characters is unintuitive. Complex data are sorted according to the real part, and the imaginary part is used to break ties.

Sorting of non-atomic data is not allowed, because the definition of ordering is too vague.


SEE ALSO:
order , rank , rev .

EXAMPLES:
mydata <- c(2, 9, 18, NA, 3, 2) # create sample object

sort(mydata) # missing values are deleted

sort(mydata, na.last = T) # put missing values at the end

sort(mydata, na.last = "") # cause an error if mydata has missing values