Learn R Programming

popEpi (version 0.3.1)

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

Description

DEPRECATED: Intended to do what shift from data.table does better since data.table 1.9.6. Shifts the values of a variable forwards or backwards to create lag or lead values. Takes a copy of the whole data and returns a new copy with the shifted variable.

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 series, using id.vars = "region" shifts the time series for each region separately
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