var_shift | R Documentation |
Sometimes we want to shift some measurements backward or forward.
dplyr::lead()
and dplyr::lag()
do this but will only operate on a single
variable. var_shift()
extends this functionality and allows shifting multiple
variables by a range of steps.
var_shift(df, vars, n, fn)
df |
Data frame containing variables to shift. |
vars |
Variable(s) to shift. |
n |
Number of observations to shift. |
fn |
The shifting function. Usually this is |
Data frame with append shifted measurements.
## Not run: shift(mtcars, c("vs", "am"), lead, 1:2) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.