title: R canonical dplyr way of replace if
body: <p>Suppose you have:</p>
  
  <pre><code>df = data.frame(a = c(1,2,NA),b = c(NA, 1,2))
  &gt; df
     a  b
  1  1 NA
  2  2  1
  3 NA  2
  </code></pre>
  
  <p>and wish to create a new column c based on a. If a is missing, then use b. This works: </p>
  
  <pre><code>df %&gt;% mutate(c= a,
                c = replace(c, is.na(a), b[is.na(a)]))
  </code></pre>
  
  <p>but (to me, just me?) looks clumsy (in the sense that I have to spell out <code>is.na(a)</code> twice). This is easier:</p>
  
  <pre><code>df %&gt;%
     rowwise() %&gt;% 
     mutate(c = a,
            c = replace(c, is.na(a), b]))
  </code></pre>
  
  <p>but it requires the extra <code>rowwise()</code> command, and I could imagine situatoins where sum of my <code>mutate</code> statesments will not work rowwise.</p>
  
  <p>Am I missing a some <code>dplyr</code> feature that makes this (very common task?) easier?</p>