lag_vars: Lag Variables up to 'n' lags

View source: R/lag_vars.R

lag_varsR Documentation

Lag Variables up to n lags

Description

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.

Details

Build the lags of a variable.

Value

A dataframe with the lags of the column specified.

Examples

library(magrittr)
df <- datasets::airmiles %>% as.vector() %>% tibble::enframe(name = "airmiles")
lag_vars(df, col = "airmiles") %>% head()


Fredo-XVII/RToolShed documentation built on March 17, 2024, 12:15 p.m.