title: fill in NA based on the last non-NA value for each group in R
body: <p>My question is I have a dataframe <code>m</code> as below </p>
  
  <pre><code>y1 =c( rep("A",5),rep("B",5))
  y2 = rep(c(1:5),2)
  y3 = y2
  y3[c(2,7,9)]=NA
  m = data.frame(y1,y2,y3)
  
     y1 y2   y3
  1   A  1    1
  2   A  2 &lt;NA&gt;
  3   A  3    3
  4   A  4    4
  5   A  5    5
  6   B  1    1
  7   B  2 &lt;NA&gt;
  8   B  3    3
  9   B  4 &lt;NA&gt;
  10  B  5    5
  </code></pre>
  
  <p>I want to fill in the NA based on the closest non-NA value "in front of" this NA. My output should look like this:</p>
  
  <pre><code>   y1 y2   y3 y4
  1   A  1    1  1
  2   A  2 &lt;NA&gt;  1
  3   A  3    3  3
  4   A  4    4  4
  5   A  5    5  5
  6   B  1    1  1
  7   B  2 &lt;NA&gt;  1
  8   B  3    3  3
  9   B  4 &lt;NA&gt;  3
  10  B  5    5  5
  </code></pre>
  
  <p>Any idea about how to use <code>dplyr</code> to achieve this goal?</p>