diff_vars: Difference Variables 'n' Lags, 'k' Differences

View source: R/diff_vars.R

diff_varsR Documentation

Difference Variables n Lags, k Differences

Description

This function takes a column and builds the differences based on the difference k between the column and the lag n specified.

Usage

diff_vars(
  df,
  col = NULL,
  lags = 1,
  diff = 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.

diff

number - specify the number of differences for differencing.

mutate_type

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

Details

Build the differences of a variable

Value

A dataframe with the lagged differences of the column specified.

Examples

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


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