R/lag_matrix.R
lag_matrix.Rd
Generates specified number of lagged variables of the given variable in the form of a tibble.
lag_matrix(variable, n = 10)
Variable to be lagged.
Number of lags. The default value is n = 10.
n = 10
A tibble.
tibble
library(dplyr) library(tibble) library(tidyr) # Adding lagged variables to an existing tibble set.seed(123) sim_data <- tibble(x_lag_000 = runif(100)) |> mutate(x_lag = lag_matrix(x_lag_000, 3)) |> unpack(x_lag, names_sep = "_")