set.seed(84322)
library(data.table)
x <- 1:10
dt <- data.table(
v1 = x,
v2 = shift(x),
v3 = shift(x, -1L),
v4 = sample(c(rep(NA, 10), x), 10),
grp = sample(1:3, 10, replace = TRUE)
)
dt_fill(dt, v2, v3, v4, id = grp, .direction = "downup")
dt_fill(dt, v2, v3, v4, id = grp)
dt_fill(dt, .direction = "up")
Run the code above in your browser using DataLab