library(dplyr)
library(timetk)
# --- VECTOR ----
# Lag
1:10 %>% lag_vec(lag = 1)
# Lead
1:10 %>% lag_vec(lag = -1)
# --- MUTATE ----
m4_daily %>%
group_by(id) %>%
mutate(lag_1 = lag_vec(value, lag = 1))
Run the code above in your browser using DataLab