Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

base-sort

Sorting a 'timeSeries' by Time Stamps


Description

Sorts a 'timeSeries' object with respect to its time stamps.

Usage

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

Arguments

x

an uni- or multivariate timeSeries object.

decreasing

a logical flag. Should we sort in increasing or decreasing order? By default FALSE.

...

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 packahe is used. order generates a permutation which rearranges the time stamps in ascending or descending order.

To find out if the series is unsorted, the function is.unsorted from R's base package can be called.

Value

Returns a sorted 'timeSeries' object, which can be increasing or decreasing in time.

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

Financial Time Series Objects (Rmetrics)

v3062.100
GPL (>= 2)
Authors
Diethelm Wuertz [aut] (original code), Tobias Setz [cre], Yohan Chalabi [ctb], Martin Maechler [ctb] (<https://orcid.org/0000-0002-8685-9910>)
Initial release
2020-01-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.