lagVars: Lagging variables

View source: R/preprocessing.R

lagVarsR Documentation

Lagging variables

Description

Creates extra column(s) with lagged variables according to the order of the data frame.

Usage

lagVars(
  dat,
  lags = 1,
  vars = vars,
  diffvars = diffvars,
  unit = "auto",
  verbose = F,
  ...
)

Arguments

dat

data.frame containing the variables to be lagged

lags

vector defining the nth lag. Positive values (e.g., 1:2) indicatw the values from the previous rows (e.g., the values from the previous (lag = 1) observation) should be taken. Negative values indicate that the values from the following rows should be taken.

vars

names of the columns in the data.frame that should be lagged

diffvars

names of columns in the data.frame of which the difference to the current row should be taken (this is particularly helpful for dealing with time variables and time differences)

unit

character value, if time variables are being lagged and the difference is taken, which time unit should be used to calculate the difference

verbose

boolean indicating about the state of the process be displayed

Value

data.frame with new columns containing the lagged variables

See Also

lagVarsNested

Examples

dat <- data.frame(a = runif(10, max = 10),
b = Sys.Date()+1:10)
lagVars(dat, lags = -1:2, vars = c("a","b"), 
diffvars = "b", unit = "hours")


timonelmer/dena documentation built on April 15, 2023, 11:51 p.m.