title: Replace NA with average of the case before and after the NA
body: <p>Say I have the following data.frame:</p>
  
  <pre><code>t&lt;-c(1,1,2,4,5,4)
  u&lt;-c(1,3,4,5,4,2)
  v&lt;-c(2,3,4,5,NA,2)
  w&lt;-c(NA,3,4,5,2,3)
  x&lt;-c(2,3,4,5,6,NA)
  
  df&lt;-data.frame(t,u,v,w,x)
  </code></pre>
  
  <p>I would like to replace the NAs with values that represent the average of the case before and after the NA, unless a row starts (row 4) or ends (row 5) with an NA. When the row begins with NA, I would like to substitute the NA with the following case. When the row ends with NA, I would like to substitute the NA with the previous case. </p>
  
  <p>Thus, I would like my output to look like: </p>
  
  <pre><code>t&lt;-c(1,1,2,4,5,4)
  u&lt;-c(1,3,4,5,4,2)
  v&lt;-c(2,3,4,5,3.5,2)
  w&lt;-c(3,3,4,5,2,3)
  x&lt;-c(2,3,4,5,6,6)
  
  df&lt;-data.frame(t,u,v,w,x)
  </code></pre>