Find the "next" or "previous" values in a vector.
It has wrapped data.table's shift
function.
lead_dt(x, n = 1L, fill = NA)
lag_dt(x, n = 1L, fill = NA)
A vector
lead_dt(1:5)
#> [1] 2 3 4 5 NA
lag_dt(1:5)
#> [1] NA 1 2 3 4
lead_dt(1:5,2)
#> [1] 3 4 5 NA NA
lead_dt(1:5,n = 2,fill = 0)
#> [1] 3 4 5 0 0