df <- data.table(
a = c(1, NA, 3, 4, 5),
b = c(NA, 2, NA, NA, 5),
groups = c("a", "a", "a", "b", "b")
)
df %>%
fill(a, b)
df %>%
fill(a, b, .by = groups)
df %>%
fill(a, b, .direction = "downup", .by = groups)
Run the code above in your browser using DataLab