Skip to contents

Sets the names of a time series list and the internal names of the zoo objects inside, stored in their attribute "name".

Usage

tsl_names_set(tsl = NULL, names = NULL)

Arguments

tsl

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

names

(optional, character vector) names to set. Must be of the same length of x. If NULL, and the list x has names, then the names of the zoo objects inside of the list are taken from the names of the list elements.

Value

time series list

Examples

#simulate time series list
tsl <- tsl_simulate(n = 3)

#assess validity
tsl <- tsl_diagnose(
  tsl = tsl
)

#list and zoo names (default)
tsl_names_get(
  tsl = tsl
)
#>   A   B   C 
#> "A" "B" "C" 

#list names
tsl_names_get(
  tsl = tsl,
  zoo = FALSE
)
#> [1] "A" "B" "C"

#renaming list items and zoo objects
#------------------------------------
tsl <- tsl_names_set(
  tsl = tsl,
  names = c("X", "Y", "Z")
)
#> distantia::zoo_name_set(): renaming zoo time series from 'A' to 'X'.
#> distantia::zoo_name_set(): renaming zoo time series from 'B' to 'Y'.
#> distantia::zoo_name_set(): renaming zoo time series from 'C' to 'Z'.

# check new names
tsl_names_get(
  tsl = tsl
)
#>   X   Y   Z 
#> "X" "Y" "Z" 

#fixing naming issues
#------------------------------------

#creating a invalid time series list
names(tsl)[2] <- "B"

# check names
tsl_names_get(
  tsl = tsl
)
#>   X   B   Z 
#> "X" "Y" "Z" 

#validate tsl
#returns NOT VALID
#recommends a solution
tsl <- tsl_diagnose(
  tsl = tsl
)
#> distantia::tsl_diagnose(): Structural issues:
#> -------------------------------------------
#> 
#>   - list and time series names must match and be unique: reset names with distantia::tsl_names_set().

#fix issue with tsl_names_set()
#uses names of zoo objects for the list items
tsl <- tsl_names_set(
  tsl = tsl
)
#> distantia::zoo_name_set(): renaming zoo time series from 'Y' to 'B'.

#validate again
tsl <- tsl_diagnose(
  tsl = tsl
)

#list names
tsl_names_get(
  tsl = tsl
)
#>   X   B   Z 
#> "X" "B" "Z"