50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

popEpi (version 0.2.1)

shift.var: Shifts a variable to create lag or lead values

Description

Shifts a variable to create lag or lead values

Usage

shift.var(data, id.vars = NULL, shift.var = NULL, value.vars = NULL,
  shift.value = -1L)

Arguments

data
a data,frame or data.table
id.vars
a character string vector of variable names; id.vars are used to identify unique subjects, for which shifting is done separately; e.g. with a panel data where region refers to different regions that all have their own time seri
shift.var
a character string vector of length one; specifies the variable according to which value.vars are shifted; e.g. id.vars = "year" means shifting forward or backward in years (given one has a var name "year")
value.vars
a character string vector; specifies the names of variables whose values that are shifted
shift.value
an integer; specifies the direction and extent of shifting; e.g. shift.value = -1L shifts one row backwards (a lag of one row) and shift.value = 2L creates a two-row lead