| create_lags | R Documentation |
Generates lagged (or lead) versions of selected numeric columns. Positive lags shift values backward in time (past values), negative lags shift forward. Useful for time series modeling.
create_lags(data, cols = NULL, lags = 1, prefix = "lag_",
group = NULL, date_col = NULL, verbose = FALSE)
data |
A data frame, matrix, or numeric vector. |
cols |
Column indices or names to create lags for. |
lags |
Vector of lag orders (positive for past, negative for future). |
prefix |
Prefix for new column names. |
group |
Optional grouping column for group-specific lags. |
date_col |
Currently ignored. Data are assumed to be in the correct time order. |
verbose |
Logical; if |
A data frame or matrix with additional lag columns.
create_lags(data[1:100, c(1, 4, 17:19)], cols = 3:5, lags = c(1, 2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.