title: Replacing NAs with values in the previous row for each group
body: <p>In <code>df</code> i would like to replace the NA values with the previous non-NA value for each id  </p>
  
  <pre><code>id&lt;-c(1,1,1,1,2,2,2)
  purchase&lt;-c(20,NA,NA,10,NA,NA,5)
  df&lt;-data.frame(id,purchase)
  
   id purchase
    1       20
    1       NA
    1       NA
    1       10
    2       NA
    2       NA
    2        5
  </code></pre>
  
  <p>The output should ideally look like:</p>
  
  <pre><code>id purchase
    1       20
    1       20
    1       20
    1       10
    2       NA
    2       NA
    2        5
  </code></pre>
  
  <p>I am aware of <a href="https://stackoverflow.com/questions/7735647/replacing-nas-with-latest-non-na-value">Replacing NAs with latest non-NA value</a>, but it does not do it per group. 
  Any help would be appreciated. </p>