title: Fill missing values with previous values by row using dplyr
body: <p>I am working with a data frame in <code>R</code> which has some missing values across rows. Data frame is next (<code>dput</code> added in the end):</p>
  <pre><code>df
    id V1 V2 V3 V4
  1 01  1  1  1 NA
  2 02  2  1 NA NA
  3 03  3  1 NA NA
  4 04  4  1  2 NA
  </code></pre>
  <p>Each row is a different <code>id</code>. As you can see the rows have missing values. I would like to know how can I get a dataframe completed in this style <strong>without using reshape to long or pivot as my real data is very large</strong>:</p>
  <pre><code>df
    id V1 V2 V3 V4
  1 01  1  1  1  1
  2 02  2  1  1  1
  3 03  3  1  1  1
  4 04  4  1  2  2
  </code></pre>
  <p>I was trying to use <code>fill</code> from <code>tidyr</code> but at row level I am having issues. I have seen some posts where it is used along with <code>dplyr</code> function <code>across</code> but I can not find it. I have tried using <code>group_by(id)</code> and <code>rowwise</code> but I have not had success. Also only the variables/columns starting with <code>V</code> should be filled with previous values.</p>
  <p>Data is next:</p>
  <pre><code>#Data
  df &lt;- structure(list(id = c(&quot;01&quot;, &quot;02&quot;, &quot;03&quot;, &quot;04&quot;), V1 = c(1, 2, 3, 
  4), V2 = c(1, 1, 1, 1), V3 = c(1, NA, NA, 2), V4 = c(NA, NA, 
  NA, NA)), class = &quot;data.frame&quot;, row.names = c(NA, -4L))
  </code></pre>
  <p>Many thanks for your time.</p>