i wanted to fill some NA values in a data.table without groups. Please consider this extract of data.table representing time and distances:
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)
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 in j to replace each instruction
DT[2, dist:=(31091.33 + (31100-31091.33)/2)]
then
DT[5:8, dist:=(31103.27+"something"*(31124.98-31103.27)/5)]
etc...
Thanksfully,