The tsbox package provides a set of tools that are agnostic towards existing time series classes. 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.
Version 0.3.1 is now on CRAN and provides several bugfixes and extensions (see here for the full change log). A detailed overview of the package functionality is given in the documentation page (or in an older blogpost).
New and extended functionality

ts_frequency()
: changes the frequency of a time series. It is now possible to aggregate any time series to years, quarters, months, weeks, days, hours, minutes or seconds. For low to highfrequency conversion, the tempdisagg package can now convert low frequency to high frequency and has support for tsboxable objects. E.g.:library(tsbox) x < ts_tbl(EuStockMarkets) x #> # A tibble: 7,440 × 3 #> id time value #> <chr> <dttm> <dbl> #> 1 DAX 19910701 03:18:27 1629. #> 2 DAX 19910702 13:01:32 1614. #> 3 DAX 19910703 22:44:38 1607. #> 4 DAX 19910705 08:27:43 1621. #> 5 DAX 19910706 18:10:48 1618. #> # … with 7,435 more rows ts_frequency(x, "week") #> # A tibble: 1,492 × 3 #> id time value #> <chr> <date> <dbl> #> 1 DAX 19910630 1618. #> 2 DAX 19910707 1633. #> 3 DAX 19910714 1632. #> 4 DAX 19910721 1620. #> 5 DAX 19910728 1616. #> # … with 1,487 more rows

ts_index()
: returns an indexed series, with a value of 1 at the base period. This base period can now be specified more flexibly. E.g., the average of a year can defined as 1 (which is a common use case). 
ts_na_interpolation()
: A new function that wrapsimputeTS::na_interpolation()
from the imputeTS package and allows the imputation of missing values for any time series object. 
ts_first_of_period()
: A new function that replaces the date or time value by the first of the period. This is useful because tsbox usually relies on timestamps being the first of a period. The following monthly series has an offset of 14 days.ts_first_of_period()
changes the timestamp to the first date of each month:x < ts_lag(ts_tbl(mdeaths), "14 days") x #> # A tibble: 72 × 2 #> time value #> <date> <dbl> #> 1 19740115 2134 #> 2 19740215 1863 #> 3 19740315 1877 #> 4 19740415 1877 #> 5 19740515 1492 #> # … with 67 more rows ts_first_of_period(x) #> # A tibble: 72 × 2 #> time value #> <date> <dbl> #> 1 19740101 2134 #> 2 19740201 1863 #> 3 19740301 1877 #> 4 19740401 1877 #> 5 19740501 1492 #> # … with 67 more rows
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, tis, irts 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_dt(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)
x.irts < ts_irts(x.tibbletime)
x.tis < ts_tis(x.irts)
all.equal(ts_ts(x.tis), x.ts)
#> [1] TRUE
Use same functions for time series classes
Because this works reliably, it is easy to define a toolkit that works for all classes. So, whether we want to smooth, scale, differentiate, chain, forecast, regularize, impute or seasonally adjust a time series, we can use the same commands to whatever time series class at hand:
ts_trend(x.ts) # estimate a trend line
ts_pc(x.xts) # calculate percentage change rates (period on period)
ts_pcy(x.df) # calculate percentage change rates (year on year)
ts_lag(x.dt) # lagged series
There are many more.
Because they all start with ts_
, you can use autocomplete to see
what’s around. Most conveniently, there is a time series plot function
that works for all classes and frequencies:
ts_plot(
`Airline Passengers` = AirPassengers,
`Lynx trappings` = ts_tis(lynx),
`Deaths from Lung Diseases` = ts_xts(fdeaths),
title = "Airlines, trappings, and deaths",
subtitle = "Monthly passengers, annual trappings, monthly deaths"
)
More posts
EFS vs. NFS for RStudio on Kubernetes (AWS): Configuration and considerationsPatrick Schratz
Accessing Google's API via OAuth2Patrick Schratz
Data Scientist (80100%)cynkra team
seasonal 1.9: Accessing composite outputChristoph Sax
Google Season of Docs with R: useR! Information BoardBen Ubah
Running old versions of TeXlive with tinytexKirill Müller
tsbox 0.3.1: extended functionalityChristoph Sax
Celebrating oneyear anniversary as RStudio Full Service Certified PartnerCosima Meyer, Patrick Schratz
Deprecating a pkgdown site served via GitHub PagesPatrick Schratz, Kirill Müller
gfortran support for R on macOSPatrick Schratz
Seasonal Adjustment of Multiple SeriesChristoph Sax
Dynamic build matrix in GitHub ActionsKirill Müller
Setting up a loadbalanced Jitsi Meet instancePatrick Schratz
DevOps Expert (f/m/d, 60100%)cynkra team
Maintaining multiple identities with GitKirill Müller
Relational data models in RAngel D'az, Kirill Müller
tempdisagg: converting quarterly time series to dailyChristoph Sax
tsbox 0.2: supporting additional time series classesChristoph Sax
DevOps System Engineer (4060%)cynkra team
Introducing dm: easy juggling of tables and relationsBalthasar Sager
tsbox 0.1: classagnostic time seriesChristoph Sax
Data Scientist/Engineer (40100%)cynkra team
Time series of the world, unite!Christoph Sax
Done “Establishing DBI”!?Kirill Müller