I wanted to fill some NA values in a data.table without groups. Please consider this extract of data.table representing time and distances:
library(data.table)
df <- data.frame(time = seq(7173, 7195, 1), dist = c(31091.33, NA, 31100.00, 31103.27, NA, NA, NA, NA, 31124.98, NA,31132.81, NA, NA, NA, NA, 31154.19, NA, 31161.47, NA, NA, NA, NA, 31182.97))
DT<- data.table(df)
Run Code Online (Sandbox Code Playgroud)
I want in the DT data.table, to fill NA values with a function depending on non-NA value before/after. As an example, writing a function …