lag
positions after it. For the last
lag
elemnts, this distance does not exist, so NA is used as a placeholder.
The returned vector is of the same length as the input vector.
lagDistance(vec, lag = 1, reverse = FALSE)
vec[i+lag] - vec[i]
. When set to TRUE, calculate vec[i] - vec[i+lag]