Learn R Programming

translateSPSS2R (version 1.0.0)

computeLag: Moves cases of variables

Description

computeLag shifts the dataset forward or backward by a given number of observations.

Usage

computeLag(x, move = 0, value = NA)

Arguments

x
a (non-empty) data.frame, data.table object or input data of class "xpssFrame".
move
atomic integer, either positive or negative that defines the cases to move. The algebraic sign indicates the direction.
value
atomic numeric or atomic character value that replaces the skipped cases.

Value

  • Output is the shifted, respectively "lagged" input vector. Length of the new lagged vector is identical with the length of the input vector.

Details

Creates shifted data dependent upon the direction in which the data got moved. A positive indicator refers a shift to the right side, a negative indicator refers a shift of the data to the left side. Empty cases get filled with NA.

Examples

Run this code
data(fromXPSS)
computeLag(x=fromXPSS$V6, move = 2, value = NA)

Run the code above in your browser using DataLab