I have a data set with body temperatures taken every minute for 8 hours. I removed aberrant data and now have NA values, sometimes just one alone, and sometimes more then 10 in a row. I would like to replace the missing data using linear interpolation.
I tried different things but I could'nt make 'approx' to work (NA values stayed NA...) or even find a way to specify to R to use the value before (same column, minus 1 row) or the value after (same column, + 1 row). in this examples, where I try to replace just one NA, the [+1] and [-1] are just read as [1], so it doesn't work
df$var1_lini <- ifelse (!is.na(df$var1),df$var1,
ifelse (!is.na(df$var[+1]),df$var[-1]+(df$var1[-1]+df$var1[+1])/2,NA))
i'm open to any form of solution I am a beginner so a detailed answer would be great! Thank you
Eve
library(zoo); help("na.approx")
– Roland