title: linear interpolation in time series in R
body: <p>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.</p>
  
  <p>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</p>
  
  <pre><code>df$var1_lini &lt;- ifelse (!is.na(df$var1),df$var1,
                  ifelse (!is.na(df$var[+1]),df$var[-1]+(df$var1[-1]+df$var1[+1])/2,NA))
  </code></pre>
  
  <p>i'm open to any form of solution
  I am a beginner so a detailed answer would be great!
  Thank you</p>
  
  <p>Eve</p>