This function builds lags of a variable up to the n lag.

Usage,
lag_vars(df, col = NULL, lags = 1, mutate_type = c("mutate", "trans"))

Arguments

df

dataframe or tibble

col

string - specify the column/field/variable for differencing.

lags

number - specify the number of lags for differencing.

mutate_type

string - select whether to mutate() or transmute() from dplyr.

Value

A dataframe with the lags of the column specified.

Details

Build the lags of a variable.

Examples

library(magrittr)
df <- datasets::airmiles %>% as.vector() %>% tibble::enframe(name = "airmiles")
lag_vars(df, col = "airmiles") %>% head()
#> # A tibble: 6 x 3
#>   airmiles value airmiles_lag_1
#>      <int> <dbl>          <int>
#> 1        1   412             NA
#> 2        2   480              1
#> 3        3   683              2
#> 4        4  1052              3
#> 5        5  1385              4
#> 6        6  1418              5