lagk: Create a lagged variable

View source: R/utils.R

lagkR Documentation

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)

Arguments

x

the variable to lag

k

the length to lag it

by

a variable to lag by. Must be sorted.

Value

a vector of the lagged values

Examples

lagk(1:4, 1)

JWileymisc documentation built on Oct. 5, 2023, 5:06 p.m.