Learn R Programming

JWileymisc (version 1.4.1)

lagk: Create a lagged variable

Description

Given a variable, create a k lagged version, optionally do it by a grouping factor, such as an ID.

Usage

lagk(x, k = 1, by)

Value

a vector of the lagged values

Arguments

x

the variable to lag

k

the length to lag it

by

a variable to lag by. Must be sorted.

Examples

Run this code
lagk(1:4, 1)

Run the code above in your browser using DataLab