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

subset.DTSg

Time Series Subset


Description

Filter rows and/or select columns of a DTSg object.

Usage

## S3 method for class 'DTSg'
subset(
  x,
  i,
  cols = self$cols(),
  funby = NULL,
  ignoreDST = FALSE,
  na.status = "implicit",
  clone = getOption("DTSgClone"),
  multiplier = 1L,
  funbyHelpers = NULL,
  ...
)

Arguments

x

A DTSg object (S3 method only).

i

An integerish vector indexing rows (positive numbers pick and negative numbers omit rows) or a filter expression accepted by the i argument of data.table. Filter expressions can contain the special symbol .N.

cols

A character vector specifying the columns to select. The .dateTime column is always selected and cannot be part of it.

funby

One of the temporal aggregation level functions described in TALFs or a user defined temporal aggregation level function. Can be used to, for instance, select the last two observations of a certain temporal level. See examples and aggregate for further information.

ignoreDST

A logical specifying if day saving time is ignored during formation of the temporal level. See aggregate for further information.

na.status

A character string. Either "explicit", which makes missing timestamps according to the recognised periodicity explicit, or "implicit", which removes timestamps with missing values on all value columns. See details for further information.

clone

A logical specifying if the object is modified in place or if a clone (copy) is made beforehand.

multiplier

A positive integerish value “multiplying” the temporal aggregation level of certain TALFs. See aggregate for further information.

funbyHelpers

An optional list with helper data passed on to funby. See aggregate for further information.

...

Not used (S3 method only).

Details

Please note that filtering rows and having or making missing timestamps explicit equals to setting the values of all other timestamps to missing. The default value of na.status is therefore "implicit". To simply filter for a consecutive range of a DTSg object while leaving na.status untouched, alter is probably the better choice.

Value

Returns a DTSg object.

See Also

Examples

# new DTSg object
x <- DTSg$new(values = flow)

# filter for the first six rows
## R6 method
x$subset(i = 1:6)

## S3 method
subset(x = x, i = 1:6)

# filter for the last two observations per year
## R6 method
x$subset(i = (.N - 1):.N, funby = function(x, ...) {data.table::year(x)})

## S3 method
subset(x = x, i = (.N - 1):.N, funby = function(x, ...) {data.table::year(x)})

DTSg

A Class for Working with Time Series Based on 'data.table' and 'R6' with Largely Optional Reference Semantics

v0.7.0
MIT + file LICENSE
Authors
Gerold Hepp [aut, cre]
Initial release

We don't support your browser anymore

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