Fast replacement of dplyr::lag for the simple case of n = 1L
and always supplying a new value to insert at the beginning of the vector.
Usage
fastlag(x, first)
Value
a vector that begins with first and is followed by x
with its final value removed
Arguments
x
A vector (length(x) > 0)
first
A single value (length(first) == 1)
Details
Important: this function is fast because it provides minimal safety checks.
It relies on the
coercion
rules of c. For best results, x and first
should be the same type of atomic vector, though it should be fine to mix
numeric and integer vectors as long as your own code also
doesn't rely on this distinction. It can also work on lists if needed.