Learn R Programming

DTSg (version 0.6.0)

subset.DTSg: Subset Time Series

Description

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

Usage

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

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. Please note that filtering rows and having or making missing timestamps explicit equals to setting the values of all other timestamps to missing. Its default value is therefore "implicit". To simply subset a complete range of a DTSg object while leaving na.status untouched, alter is probably the better choice.

clone

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

Not used (S3 method only).

Value

Returns a DTSg object.

See Also

DTSg, data.table, .N, cols, TALFs, alter

Examples

Run this code
# NOT RUN {
# new DTSg object
x <- DTSg$new(values = flow)

# filter for the last six rows
## R6 method
x$subset(i = (.N - 5):.N)

## S3 method
subset(x = x, i = (.N - 5):.N)

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

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

# }

Run the code above in your browser using DataLab