小编Arn*_*udR的帖子

data.table linearly interpolating NA values without groups

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 …

r data.table

16
推荐指数
5
解决办法
393
查看次数

标签 统计

data.table ×1

r ×1