Find the "next" or "previous" values in a vector. Useful for comparing values ahead of or behind
the current values.
Usage
lead(x, n = 1L, default = NA, order_by = NULL, ...)
Arguments
x a vector of values
n a postive integer of length 1, giving the number of positions to lead or lag by
default value used for non-existant rows. Defaults to NA.
order_by override the default ordering to use another vector
... Needed for compatibility with lag generic.
Examples
lead(1:10, 1)
lead(1:10, 2)
lag(1:10, 1)
lead(1:10, 1)
x <- runif(5)
cbind(ahead = lead(x), x, behind = lag(x))