Integrating new classes to tsbox is relatively easy. The following discusses some of the classes, starting with a very new one.
The tsibble package provides a data class of
tbl_ts to store time series data frames in a ‘tidy’ manner. A tsibble consists of a time index, keys and other measured variables and is built on top of the tibble.
tsbox converters can be applied to tsibbles the usual way:
suppressMessages(library(tsibble)) library(tsbox) x.tsbl <- ts_tsibble(AirPassengers) head(x.tsbl) head(ts_xts(x.tsbl)) head(ts_ts(x.tsbl)) head(ts_df(x.tsbl)) # etc.
Here is a longer example, using the example from the tsibble documentation.
tsbox want deals with multiple time series in the long format, so we transform the variables into the desired form, using
suppressMessages(library(dplyr)) dta.tbl <- nycflights13::weather %>% select(origin, time = time_hour, temp, humid, precip) %>% ts_long()
Next, we convert the tibble to a tsibble. Because tsbox guesses the time and the value and the key columns, calling
ts_tsibble is sufficient:
dta.tsibble <- dta.tbl %>% ts_tsibble()
With a long tsibble at hand, we can apply all usual functions from tsbox:
Because tsbox functions work identical for all ts-boxable objects, the same commands could be used, e.g., on a standard tibble:
Some special functionality is offered by the tsibble package The following shows how aggregation can be performed using tsibbles, tibbles or any ts-boxable object: