Time series toolkit with identical behavior for all time series classes: 'ts','xts', 'data.frame', 'data.table', 'tibble', 'zoo', 'timeSeries', 'tsibble'. Also converts reliably between these classes.
The R ecosystem knows a vast number of time series standards. Instead of creating the ultimate 15th time series class, tsbox provides a set of tools that are agnostic towards the existing standards. The tools also allow you to handle time series as plain data frames, thus making it easy to deal with time series in a dplyr or data.table workflow.
To install the stable version from CRAN:
To install the development version:
tsbox is built around a set of converters, which convert time series stored as ts, xts, data.frame, data.table, tibble, zoo, tsibble, tibbletime or timeSeries to each other:
library(tsbox)x.ts <- ts_c(fdeaths, mdeaths)x.xts <- ts_xts(x.ts)x.df <- ts_df(x.xts)x.dt <- ts_df(x.df)x.tbl <- ts_tbl(x.dt)x.zoo <- ts_zoo(x.tbl)x.tsibble <- ts_tsibble(x.zoo)x.tibbletime <- ts_tibbletime(x.tsibble)x.timeSeries <- ts_timeSeries(x.tibbletime)all.equal(ts_ts(x.timeSeries), x.ts) # TRUE
Because this works reliably, it is easy to write functions that work for all classes. So whether we want to smooth, scale, differentiate, chain, forecast, regularize or seasonally adjust a time series, we can use the same commands to whatever time series class at hand:
A set of helper functions makes it easy to combine or align multiple time series of all classes:
# collect time series as multiple time seriests_c(ts_dt(EuStockMarkets), AirPassengers)ts_c(EuStockMarkets, mdeaths)# combine time series to a new, single time seriests_bind(ts_dt(mdeaths), AirPassengers)ts_bind(ts_xts(AirPassengers), ts_tbl(mdeaths))
Plotting all kinds of classes and frequencies is as simple as it should be. And we finally get a legend!
ts_plot(ts_scale(ts_c(mdeaths, austres, AirPassengers, DAX = EuStockMarkets[ ,'DAX'])))