Subset Time Series Lists by Time Series Names, Time, and/or Column Names
Source:R/tsl_subset.R
tsl_subset.Rd
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
(optional, logical) If TRUE, only columns shared across all zoo objects are returned. Default: TRUE
See also
Other tsl_management:
tsl_colnames_clean()
,
tsl_colnames_get()
,
tsl_colnames_set()
,
tsl_count_NA()
,
tsl_diagnose()
,
tsl_handle_NA()
,
tsl_names_clean()
,
tsl_names_get()
,
tsl_names_set()
,
tsl_names_test()
,
tsl_ncol()
,
tsl_nrow()
,
tsl_repair()
,
tsl_split()
,
tsl_time()
,
tsl_time_class_set()
,
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
)
#> Germany Spain Sweden
#> "Germany" "Spain" "Sweden"
#colnames
tsl_colnames_get(
tsl = tsl
)
#> $Germany
#> [1] "evi" "rainfall" "temperature"
#>
#> $Spain
#> [1] "evi" "rainfall" "temperature"
#>
#> $Sweden
#> [1] "evi" "rainfall" "temperature"
#>
#time
tsl_time(
tsl = tsl
)[, c("name", "begin", "end")]
#> name begin end
#> 1 Germany 2001-01-01 2018-12-01
#> 2 Spain 2001-01-01 2018-12-01
#> 3 Sweden 2001-01-01 2018-12-01
#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
)
#> Sweden Germany
#> "Sweden" "Germany"
#colnames
tsl_colnames_get(
tsl = tsl_new
)
#> $Sweden
#> [1] "rainfall" "temperature"
#>
#> $Germany
#> [1] "rainfall" "temperature"
#>
#time
tsl_time(
tsl = tsl_new
)[, c("name", "begin", "end")]
#> name begin end
#> 1 Sweden 2010-01-01 2015-01-01
#> 2 Germany 2010-01-01 2015-01-01