shift {regr}R Documentation

Shift a Vector, Matrix or Data.frame

Description

Shifts a vector by introducing NA's at the beginning and dropping elements at the end or vice versa. Analogous for rows of matrices and data.frames

Usage

shift(x, k = 1)

Arguments

x

vector or matrix to be shifted

k

number of elements or rows to be dropped in the end (if k is positive) or at the beginning (otherwise)

Value

shifted vector or matrix

Note

This function helps to regress a target variable on lagged (=shifted) versions of itself (autocorrelation) and/or explanatory variables (time series regression)

Author(s)

Werner A. Stahel

See Also

lag for ts objects

Examples

shift(1:5,k=2)
shift(c("a","b","c"),-1)

## need an example for time series regression!!!

[Package regr version 1.1 Index]