Analogous function for lead
and lag
in dplyr by
wrapping data.table's shift
.
lead(x, n = 1L, fill = NA)
lag(x, n = 1L, fill = NA)
A vector
lead(1:5)
#> [1] 2 3 4 5 NA
lag(1:5)
#> [1] NA 1 2 3 4
lead(1:5,2)
#> [1] 3 4 5 NA NA
lead(1:5,n = 2,fill = 0)
#> [1] 3 4 5 0 0