R: Add many lags to the data

tk_augment_lags {timetk} | R Documentation

## Add many lags to the data

### Description

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

### Usage

    tk_augment_lags(.data, .value, .lags = 1, .names = "auto")

### Arguments

`.data` | A tibble.
`.value` | A column to have a difference transformation applied
`.lags` | One or more lags for the difference(s)
`.names` | A vector of names for the new columns. Must be of same length as `.lags`.

### Details

Benefits

This is a scalable function that is:

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

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

### Value

Returns a `tibble` object describing the timeseries.

### See Also

Augment Operations:

- `tk_augment_timeseries_signature()` - Group-wise augmentation of timestamp features

- `tk_augment_holiday_signature()` - Group-wise augmentation of holiday features

- `tk_augment_slidify()` - Group-wise augmentation of rolling functions

- `tk_augment_lags()` - Group-wise augmentation of lagged data

- `tk_augment_differences()` - Group-wise augmentation of differenced data

- `tk_augment_fourier()` - Group-wise augmentation of fourier series

Underlying Function:

- `lag_vec()` - Underlying function that powers `tk_augment_lags()`

### Examples

    library(tidyverse)
    library(timetk)

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

[Package timetk version 2.0.0 Index]