trim_ts_object: Reduces the length of a time series object

Description Usage Arguments Value Examples

View source: R/HELPER_trim_ts_object.R

Description

trim_ts_object is a function to trim a time series object, either from the left (beginning) or from the right (end).

Usage

1
trim_ts_object(ts_object, max_length = Inf, from_left = T)

Arguments

ts_object

Time series object to be trimmed.

max_length

A positive integer value indicating the maximum length the resulting ts object should be.

from_left

Boolean on whether to trim from the left/beginning (from_left = T) or right/end (from_left = F) of the time series object.

Value

A trimmed time series object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ts_object <- tstools::initialize_ts_forecast_data(
      data = dummy_gasprice,
      date_col = "year_month",
      col_of_interest = "gasprice", 
      group_cols = c("state", "oil_company"), 
      xreg_cols = c("spotprice", "gemprice")
   ) %>% 
   dplyr::filter(grouping == "state = New York   &   oil_company = CompanyA") %>% 
   tstools::transform_data_to_ts_object()
trim_ts_object(ts_object = ts_object, max_length = 42, from_left = F)
trim_ts_object(ts_object = ts_object, max_length = 42, from_left = T)

ing-bank/tsforecast documentation built on Sept. 18, 2020, 9:40 a.m.