# base-sort: Sort a 'timeSeries' by time stamps In timeSeries: Financial Time Series Objects (Rmetrics)

 sort R Documentation

## Sort a 'timeSeries' by time stamps

### Description

Sort a `"timeSeries"` object with respect to its time stamps.

### Usage

``````## S4 method for signature 'timeSeries'
sort(x, decreasing = FALSE, ...)

## S4 method for signature 'timeSeries'
is.unsorted(x, na.rm = FALSE, strictly = FALSE)
``````

### Arguments

 `x` a `"timeSeries"` object. `decreasing` a logical flag. Should we sort in increasing or decreasing order? By default `FALSE`. `na.rm` a logical value, should missing values be removed? `strictly` logical indicating if the check should be for strictly increasing values. `...` optional arguments passed to other methods.

### Details

Sorts a time series either in increasing or decreasing time stamp order. Internally the function `order` from R's base package is used. `order` generates a permutation which rearranges the time stamps in ascending or descending order.

To find out if the series is unsorted, use `is.unsorted`.

### Value

for `sort`, a `"timeSeries"` object,

for the `is.unsorted` method, `TRUE` or `FALSE`

### Examples

``````
## Monthly Calendar Series -
x <- daily2monthly(LPP2005REC[, 1:2])[3:14, ]

## Resample the Series with respect to the time stamps -
resampled <- sample(x)
resampled
is.unsorted(resampled)

## Now sort the serie in decreasing time order -
sorted <- sort(resampled, , decreasing = TRUE)
sorted
is.unsorted(sorted)

## Is the reverted series ordered? -
reverted <- rev(sorted)
reverted
is.unsorted(reverted)
``````

timeSeries documentation built on Aug. 26, 2023, 5:08 p.m.