Subsetting time series
basesubsetting.Rd
Objects from class "timeSeries"
can be subsetted in different
ways. Methods are defined for the subsetting operators "$"
,
"["
and their assignment versions, as well as for some related
functions from base R. A function to drop or extract outliers is also
described here.
Usage
# S3 method for timeSeries
head(x, n = 6, recordIDs = FALSE, ...)
# S3 method for timeSeries
tail(x, n = 6, recordIDs = FALSE, ...)
outlier(x, sd = 5, complement = TRUE, ...)
Arguments
 x
an object of class
timeSeries
.
 n
an integer specifying the number of lines to be returned. By default
n=6
. recordIDs
a logical value. Should the
recordIDs
be returned together with the data matrix and time series positions? sd

a numeric value of standard deviations, e.g. 10 means that values larger or smaller than ten times the standard deviation will be removed from the series.
 complement

a logical flag. If
TRUE
, the default, return the series free of outliers. IfFALSE
, return the outliers series.
 ...
arguments passed to other methods.
Details
The "timeSeries"
methods for the subsetting operators "$"
,
"["
and their assignment versions, as well as for the functions
head
and tail
are meant to do what the user expects.
TODO: Further details are needed here, despite the above paragraph.
outlier
drops the outliers if complement = TRUE
and
returns only them if complement = FALSE
.
All functions described here return "timeSeries"
objects.
See also window
which extracts the subseries between
two datetimes.
Examples
## Create an Artificial 'timeSeries' Object
setRmetricsOptions(myFinCenter = "GMT")
charvec < timeCalendar()
set.seed(4711)
data < matrix(exp(cumsum(rnorm(12, sd = 0.1))))
tS < timeSeries(data, charvec, units = "tS")
tS
#> GMT
#> tS
#> 20240101 1.1995824
#> 20240201 1.3757753
#> 20240301 1.5506114
#> 20240401 1.4887865
#> 20240501 1.4005479
#> 20240601 1.2043889
#> 20240701 1.3069906
#> 20240801 1.1867998
#> 20240901 1.1815277
#> 20241001 1.2389245
#> 20241101 1.1230263
#> 20241201 0.9596526
## Subset Series by Counts "["
tS[1:3, ]
#> GMT
#> tS
#> 20240101 1.199582
#> 20240201 1.375775
#> 20240301 1.550611
## Subset the Head of the Series
head(tS, 6)
#> GMT
#> tS
#> 20240101 1.199582
#> 20240201 1.375775
#> 20240301 1.550611
#> 20240401 1.488787
#> 20240501 1.400548
#> 20240601 1.204389