Sort into Ascending Numeric or Alphabetic or Time (Position) Order

DESCRIPTION:

Returns a vector or bdVector, a timeSeries (signalSeries) or a bdTimeSeries (bdSignalSeries) that 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 or bdVector or a series or a bdSeries object; missing values ( NAs) are allowed. For numeric vectors or bdNumerics, infinite values are also allowed.

OPTIONAL ARGUMENTS:

partial
vector or bdVector of indices (in ascending order) into data for partial sorting.
na.last
a length 1 vector or bdVector. 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 or bdVector with its data sorted into ascending order. If x is a series or bdSeries object, the timeSeries (bdTimeSeries) or signalSeries (bdSignalSeries) is sorted by time (position).

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 or bdVector.

Infinite values are allowed and are sorted appropriately. Character data are sorted according to the ASCII 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.

To sort a series or bdSeries object x by selected data columns, use order or rank.

SEE ALSO:

, , , , .

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