step_lead_lag: step_lead_lag

View source: R/api_recipes.R

step_lead_lagR Documentation

step_lead_lag

Description

Lag or lead a column or columns. This requires a sorted and regular time series.

Usage

step_lead_lag(
  .rec,
  terms,
  lag,
  n_shift = 0L,
  n_subset = 1L,
  role = "predictor",
  skip = FALSE,
  keep_original_cols = FALSE,
  ...
)

Arguments

.rec

the R6 recipe object.

terms

the unquoted names of the variables to use or a selector function. terms replaces the '...' of the recipes package but requires variables to be included within 'c()'. For example to include variables x and y you would write 'c(x,y)' in the hydrorecipes package.

lag

integer vector - number of samples to lag or lead. Negative numbers indicate leading a vector.

n_shift

integer - number of values to shift the starting position when n_subset is not equal to 0. The value of n_shift has to be less than 'n_subset'.

n_subset

integer - spacing between adjacent samples in the result.

role

character - the name of the role

skip

logical - should the step be skipped

keep_original_cols

logical - keep the original columns or replace them

...

additional arguments

Value

an updated recipe

Examples

dat <- data.frame(x = rnorm(10), y = rnorm(10))

rec <- recipe(y~x, data = dat) |>
       step_lead_lag(x, lag = 1)

rec <- recipe(y~x, data = dat) |>
       step_lead_lag(x, lag = 1, n_subset = 5)

rec <- recipe(y~x, data = dat) |>
       step_lead_lag(x, lag = 1, n_shift = 2, n_subset = 5)


jkennel/hydrorecipes documentation built on Dec. 24, 2024, 5:38 p.m.