title: R: complete cells below by adding 1 each time
body: <p>I have a dataframe with a column about time and this column contains some <code>NA</code>. I would like to fill these cells with the year before + 1 (if the missing cell is not the beginning of the serie). Here's a reproducible example:</p>
  
  <pre><code>df &lt;- data.frame(x = c("A", "B", "C", "A", "B", "C"),
                   y = c(2000, NA, NA, 2000, 2001, 2002))
  </code></pre>
  
  <p>I tried to follow <a href="https://stackoverflow.com/questions/46130246/filling-missing-dates-in-a-grouped-time-series-a-tidyverse-way">this post</a></p>
  
  <pre><code>df &lt;- df %&gt;%
    complete(y = seq(min(y), max(y), by = "year"))
  </code></pre>
  
  <p>but I can't find out how to do so. Any idea?</p>
  
  <p><strong>Edit:</strong> expected output:</p>
  
  <pre><code>df &lt;- data.frame(x = c("A", "B", "C", "A", "B", "C"),
                   y = c(2000, 2001, 2002, 2000, 2001, 2002))
  </code></pre>
  
  <p><strong>Note:</strong> I would prefer a <code>dplyr</code> solution.</p>
  
  <p><strong>Note 2 (October 23rd 2019):</strong> The three answers so far are good but quite complicated. I'm really surprised that it is not possible to do that simply (for example, having the possibility to add a lag in the <code>fill</code> function would be really useful I think).</p>