lag_dfr.Rd
lag_dfr: Lag columns of a data frame
lag_dfr(df, col_name, lags)
df | The dataframe containing the time series data |
---|---|
col_name | The column name (single) to be used to create the lagged variables |
lags | Number of lags to create for the column |
x<- c(2,3,5,7,9,9,5,3) z <- c(6,9,3,3,3,4,5,7) y <- 1:8 df <- data.frame(Y = y, X = x, Z =z) lag_dfr(df, "X", 1:3)#> X_1 X_2 X_3 #> 1 2 2 2 #> 2 3 3 3 #> 3 5 5 5 #> 4 7 7 7 #> 5 9 9 9 #> 6 9 9 9 #> 7 5 5 5 #> 8 3 3 3