Class-Agnostic Time Series

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.


Build Status Build status codecov CRAN_Status_Badge

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:

install.packages("tsbox")

To install the development version:

remotes::install_github("christophsax/tsbox")

Convert everything to everything

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

Use same functions for time series classes

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:

ts_trend(x.ts) 
ts_pc(x.xts)
ts_pcy(x.df)
ts_lag(x.dt)

Time series of the world, unite!

A set of helper functions makes it easy to combine or align multiple time series of all classes:

# collect time series as multiple time series
ts_c(ts_dt(EuStockMarkets), AirPassengers)
ts_c(EuStockMarkets, mdeaths)
 
# combine time series to a new, single time series
ts_bind(ts_dt(mdeaths), AirPassengers)
ts_bind(ts_xts(AirPassengers), ts_tbl(mdeaths))

And plot just about everything

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'])))

News

tsbox 0.1.0 (2019-04-03)

Changes

  • Rectangular structures (data.frame, tibble, data.table) keep explicit NAs by default. Use ts_na_omit() to make explicit NAs implicit. As previously, ts_regular() makes implicit NAs explicit.

New Functions and Features

  • ts_default, new function to change column names to defaults (time, value), so that no auto detection is performed afterwards (#118)
  • ts_summary, returns a data frame with summary information of a ts-boxable object. Also used to extract time series properties (ts_summary(x)$start, ts_summary(x)$freq, etc.)
  • ts_regular gains fill argument, to specify replacement value for NA (#101)
  • ts_pc, ts_pcy, ts_diff, ts_diffy have been rewritten and are much faster. They now return a series of the same length as the input, with NAs at the beginning.
  • ts_pca, new function to calculate annualized percentage change rate
  • ts_span gains extend argument, to add explicit NAs

Bug fixes

  • ts_apply pass on arguments. This allows functions generated by ts_ to pass on additional arguments. E.g., ts_seas(AirPassengers, x11 = "") (#115, #103)
  • unnamed tslist objects of length 1 don't get an id anymore (#116)
  • ts_span various fixes, boundary specification by shift string ("1 year") or period now works as expected, also for non-heuristic series, such as EuStockMarkets (#106)
  • time column of daily data is treated as Date and survives two way conversion (#114, #137)
  • ts_pick, error if picked series is not in data (#100)
  • error when data contains duplicated series (#102)
  • ts_plot, improved axis labels for high frequency series (#117)
  • fixed tsibble to anything conversion

Deprecated

  • ts_start, ts_end, use ts_summary(x)$start and ts_summary(x)$end instead.

tsbox 0.0.3 (2018-06-18)

Features

  • Support for tibbletime time series (#90)

Bug fixes

  • Automatically detect numbers or text from 1600 to 2200 as time column (#92)
  • Fix to correctly ensure uniqueness of non unique id combinations (#93)
  • Fix to correctly parse POSIXct columns for monthly data in different time zones. Remove two way testing for daily series with POSIXct columns. This should fix mac binary build on CRAN (#97)

tsbox 0.0.2 (2018-05-12)

Features

  • initial version

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("tsbox")

0.1.0 by Christoph Sax, 4 months ago


https://www.tsbox.help


Report a bug at https://github.com/christophsax/tsbox/issues


Browse source code at https://github.com/cran/tsbox


Authors: Christoph Sax [aut, cre]


Documentation:   PDF Manual  


Task views: Time Series Analysis


GPL-3 license


Imports data.table, anytime

Suggests testthat, dplyr, tibble, forecast, seasonal, dygraphs, xts, ggplot2, scales, knitr, rmarkdown, tsibble, tibbletime, zoo, timeSeries, nycflights13


See at CRAN