powered by
Given a variable, create a k lagged version, optionally do it by a grouping factor, such as an ID.
lagk(x, k = 1, by)
a vector of the lagged values
the variable to lag
the length to lag it
a variable to lag by. Must be sorted.
lagk(1:4, 1)
Run the code above in your browser using DataLab