Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

tk_augment_differences

Add many differenced columns to the data


Description

A handy function for adding multiple lagged difference values to a data frame. Works with dplyr groups too.

Usage

tk_augment_differences(
  .data,
  .value,
  .lags = 1,
  .differences = 1,
  .log = FALSE,
  .names = "auto"
)

Arguments

.data

A tibble.

.value

One or more column(s) to have a transformation applied. Usage of tidyselect functions (e.g. contains()) can be used to select multiple columns.

.lags

One or more lags for the difference(s)

.differences

The number of differences to apply.

.log

If TRUE, applies log-differences.

.names

A vector of names for the new columns. Must be of same length as the number of output columns. Use "auto" to automatically rename the columns.

Details

Benefits

This is a scalable function that is:

  • Designed to work with grouped data using dplyr::group_by()

  • Add multiple differences by adding a sequence of differences using the .lags argument (e.g. lags = 1:20)

Value

Returns a tibble object describing the timeseries.

See Also

Augment Operations:

Underlying Function:

  • diff_vec() - Underlying function that powers tk_augment_differences()

Examples

library(tidyverse)
library(timetk)

m4_monthly %>%
    group_by(id) %>%
    tk_augment_differences(value, .lags = 1:20)

timetk

A Tool Kit for Working with Time Series in R

v2.6.1
GPL (>= 3)
Authors
Matt Dancho [aut, cre], Davis Vaughan [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.