tsbox 0.3.1: extended functionality
Want to share your content on Rbloggers? click here if you have a blog, or here if you don't.
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 wraps imputeTS::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