title: Merge NA replacement
body: <p>I'm trying to merge two data frames on a unique id and year. In SQL language I'm trying to do a left outer join, so in merge that is all.x=TRUE. Some elements of the y dataframe dont have all of the values (unique id,year combinations) in the x DF. In the case of a missing match I want to merge the row from the y data frame that has the same unique id as in the x data frame, but using the first year that I have prior to the missing one. Any suggestions on how to approach this merge? Thanks a lot!</p>
  
  <p><em>Edit</em> Wanted to make it more concrete</p>
  
  <p>Dataframe x:</p>
  
  <pre><code>Id  year    var1 
  1   2010    100
  1   2011    105
  1   2012    110
  2   2010    100 
  2   2011    105
  2   2012    106
  </code></pre>
  
  <p>Dataframe y: </p>
  
  <pre><code>Id  year    var2    var3
  1   2010    5       7
  1   2011    10      8
  2   2010    9       6
  </code></pre>
  
  <p>Desired merge:</p>
  
  <pre><code>Id  year    var1    var2    var3
  1   2010    100     5       7
  1   2011    105     10      8
  1   2012    110     10      8
  2   2010    100     9       6
  2   2011    105     9       6
  2   2012    106     9       6
  </code></pre>