powered by
A handy function for adding multiple lagged difference values to a data frame. Works with dplyr groups too.
dplyr
tk_augment_differences( .data, .value, .lags = 1, .differences = 1, .log = FALSE, .names = "auto" )
A tibble.
One or more column(s) to have a transformation applied. Usage of tidyselect functions (e.g. contains()) can be used to select multiple columns.
tidyselect
contains()
One or more lags for the difference(s)
The number of differences to apply.
If TRUE, applies log-differences.
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.
Returns a tibble object describing the timeseries.
tibble
Benefits
This is a scalable function that is:
Designed to work with grouped data using dplyr::group_by()
dplyr::group_by()
Add multiple differences by adding a sequence of differences using the .lags argument (e.g. lags = 1:20)
.lags
lags = 1:20
Augment Operations:
tk_augment_timeseries_signature() - Group-wise augmentation of timestamp features
tk_augment_timeseries_signature()
tk_augment_holiday_signature() - Group-wise augmentation of holiday features
tk_augment_holiday_signature()
tk_augment_slidify() - Group-wise augmentation of rolling functions
tk_augment_slidify()
tk_augment_lags() - Group-wise augmentation of lagged data
tk_augment_lags()
tk_augment_differences() - Group-wise augmentation of differenced data
tk_augment_differences()
tk_augment_fourier() - Group-wise augmentation of fourier series
tk_augment_fourier()
Underlying Function:
diff_vec() - Underlying function that powers tk_augment_differences()
diff_vec()
# NOT RUN { library(tidyverse) library(timetk) m4_monthly %>% group_by(id) %>% tk_augment_differences(value, .lags = 1:20) # }
Run the code above in your browser using DataLab