tsl_subset: Subset Time Series Lists by Time Series Names, Time, and/or...

View source: R/tsl_subset.R

tsl_subsetR Documentation

Subset Time Series Lists by Time Series Names, Time, and/or Column Names

Description

Subset Time Series Lists by Time Series Names, Time, and/or Column Names

Usage

tsl_subset(
  tsl = NULL,
  names = NULL,
  colnames = NULL,
  time = NULL,
  numeric_cols = TRUE,
  shared_cols = TRUE
)

Arguments

tsl

(required, list) Time series list. Default: NULL

names

(optional, character or numeric vector) Character vector of names or numeric vector with list indices. If NULL, all time series are kept. Default: NULL

colnames

(optional, character vector) Column names of the zoo objects in tsl. If NULL, all columns are returned. Default: NULL

time

(optional, numeric vector) time vector of length two used to subset rows by time. If NULL, all rows in tsl are preserved. Default: NULL

numeric_cols

(optional, logical) If TRUE, only the numeric columns of the zoo objects are returned. Default: TRUE

shared_cols

(optional, logical) If TRUE, only columns shared across all zoo objects are returned. Default: TRUE

Value

time series list

See Also

Other tsl_management: tsl_burst(), tsl_colnames_clean(), tsl_colnames_get(), tsl_colnames_prefix(), tsl_colnames_set(), tsl_colnames_suffix(), tsl_count_NA(), tsl_diagnose(), tsl_handle_NA(), tsl_join(), tsl_names_clean(), tsl_names_get(), tsl_names_set(), tsl_names_test(), tsl_ncol(), tsl_nrow(), tsl_repair(), tsl_time(), tsl_to_df()

Examples

#initialize time series list
tsl <- tsl_initialize(
  x = fagus_dynamics,
  name_column = "name",
  time_column = "time"
)

#checking available dimensions

#names
tsl_names_get(
  tsl = tsl
)

#colnames
tsl_colnames_get(
  tsl = tsl
)

#time
tsl_time(
  tsl = tsl
)[, c("name", "begin", "end")]

#subset
tsl_new <- tsl_subset(
  tsl = tsl,
  names = c("Sweden", "Germany"),
  colnames = c("rainfall", "temperature"),
  time = c("2010-01-01", "2015-01-01")
)

#check new dimensions

#names
tsl_names_get(
  tsl = tsl_new
)

#colnames
tsl_colnames_get(
  tsl = tsl_new
)

#time
tsl_time(
  tsl = tsl_new
)[, c("name", "begin", "end")]

distantia documentation built on April 4, 2025, 5:42 a.m.