CollapsABEL (version 0.10.11)

lagDistance: Distance with lag

Description

Calculate the distance between each element in a numeric vector and the element that is 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.

Usage

lagDistance(vec, lag = 1, reverse = FALSE)

Arguments

vec
numeric.
lag
integer.
reverse
logical. Default to FALSE, i.e. calculate vec[i+lag] - vec[i]. When set to TRUE, calculate vec[i] - vec[i+lag]

Value

numeric.