setna(x, ..., along_with = NULL, by = NULL, roll = TRUE, rollends = if
(roll == "nearest") c(TRUE, TRUE) else if (roll >= 0) c(FALSE, TRUE) else
c(TRUE, FALSE))setna_(x, ..., vars, along_with = NULL, by = NULL, roll = TRUE,
rollends = if (roll == "nearest") c(TRUE, TRUE) else if (roll >= 0) c(FALSE,
TRUE) else c(TRUE, FALSE))
library(data.table)
DT <- data.table(
id = c(1, 1, 1, 1, 2, 2),
date = c(1992, 1989, 1991, 1993, 1992, 1991),
value = c(NA, NA, 3, NA, 3.2, 5.2)
)
DT1 <- copy(DT)
setkey(DT1, id, date)
DT2 <- copy(DT1)
DT3 <- copy(DT1)
setna(DT, value, along_with = date, by = id)
setna(DT1)
setna(DT2, value, rollends = TRUE)
setna(DT3, value, roll = "nearest")
Run the code above in your browser using DataLab