| lag_matrix | R Documentation |
Generates specified number of lagged variables of the given variable in the form of a tibble.
lag_matrix(variable, n = 10)
variable |
Variable to be lagged. |
n |
Number of lags. The default value is |
A 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 = "_")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.