tk_augment_slidify: Add many rolling window calculations to the data

View source: R/augment-tk_augment_slidify.R

tk_augment_slidifyR Documentation

Add many rolling window calculations to the data


Quickly use any function as a rolling function and apply to multiple .periods. Works with dplyr groups too.


  .align = c("center", "left", "right"),
  .partial = 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.


One or more periods for the rolling window(s)


A summary ⁠[function / formula]⁠,


Optional arguments for the summary function


Rolling functions generate .period - 1 fewer values than the incoming vector. Thus, the vector needs to be aligned. Select one of "center", "left", or "right".


.partial Should the moving window be allowed to return partial (incomplete) windows instead of NA values. Set to FALSE by default, but can be switched to TRUE to remove NA's.


A vector of names for the new columns. Must be of same length as .period. Default is "auto".


tk_augment_slidify() scales the slidify_vec() function to multiple time series .periods. See slidify_vec() for examples and usage of the core function arguments.


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:

  • slidify_vec() - The underlying function that powers tk_augment_slidify()



# Single Column | Multiple Rolling Windows
FANG %>%
    select(symbol, date, adjusted) %>%
    group_by(symbol) %>%
        .value   = contains("adjust"),
        # Multiple rolling windows
        .period  = c(10, 30, 60, 90),
        .f       = mean,
        .partial = TRUE,
        .names   = stringr::str_c("MA_", c(10, 30, 60, 90))
    ) %>%

# Multiple Columns | Multiple Rolling Windows
FANG %>%
    select(symbol, date, adjusted, volume) %>%
    group_by(symbol) %>%
        .value  = c(adjusted, volume),
        .period  = c(10, 30, 60, 90),
        .f       = mean,
        .partial = TRUE
    ) %>%

timetk documentation built on Nov. 2, 2023, 6:18 p.m.