title: R: fill missing value with prior values
body: <p>I have a dataframe that looks like this: </p>
  
  <pre><code>d &lt;- data.frame(county = c("Abilene", rep(NA, 5), "Cook", rep(NA, 4), "Blah", NA, "Allegheny", rep(NA, 3)))
  
        county
  1    Abilene
  2       &lt;NA&gt;
  3       &lt;NA&gt;
  4       &lt;NA&gt;
  5       &lt;NA&gt;
  6       &lt;NA&gt;
  7       Cook
  8       &lt;NA&gt;
  9       &lt;NA&gt;
  10      &lt;NA&gt;
  11      &lt;NA&gt;
  12      Blah
  13      &lt;NA&gt;
  14 Allegheny
  15      &lt;NA&gt;
  16      &lt;NA&gt;
  17      &lt;NA&gt;
  </code></pre>
  
  <p>I want to fill in the <code>&lt;NA&gt;</code> with the value of the previous non-missing county name. In other words, I want to end up with this: </p>
  
  <pre><code>  county
  1       Abilene
  2       Abilene
  3       Abilene
  4       Abilene
  5       Abilene
  6       Abilene
  7       Cook
  8       Cook
  9       Cook
  10      Cook
  11      Cook
  12      Blah
  13      Blah
  14      Allegheny
  15      Allegheny
  16      Allegheny
  17      Allegheny
  </code></pre>
  
  <p>So far, I have been looping over every value in <code>d$county</code>, updating a temporary variable with the name of every non-empty county value, and refilling each cell. This is very slow with a large dataframe. I would prefer to do this in <code>dplyr</code>, though am open to any other solution as well. </p>