title: Using dplyr mutate_at when a function takes multiple arguments which are different columns
body: <p>I have a <code>data.frame</code> with a large number of columns whose names follow a pattern. Such as:</p>
  
  <pre><code>df &lt;- data.frame(
    x_1 = c(1, NA, 3), 
    x_2 = c(1, 2, 4), 
    y_1 = c(NA, 2, 1), 
    y_2 = c(5, 6, 7)
  )
  </code></pre>
  
  <p>I would like to apply <code>mutate_at</code> to perform the same operation on each pair of columns. As in:</p>
  
  <pre><code>df %&gt;%
    mutate(
      x = ifelse(is.na(x_1), x_2, x_1), 
      y = ifelse(is.na(y_1), y_2, y_1)
    )
  </code></pre>
  
  <p>Is there a way I can do that with <code>mutate_at</code>/<code>mutate_each</code>?  </p>
  
  <p>This:</p>
  
  <pre><code>df %&gt;%
    mutate_each(vars(x_1, y_1), funs(ifelse(is.na(.), vars(x_2, y_2), .)))
  </code></pre>
  
  <p>and various variations I've tried all fail.</p>
  
  <p>The question is similar to <a href="https://stackoverflow.com/questions/39209987/using-functions-of-multiple-columns-in-a-dplyr-mutate-at-call">Using functions of multiple columns in a dplyr mutate_at call</a>, but different in that the second argument to the function call is not a single column, but a different column for each column in vars. </p>
  
  <p>Thanks in advance. </p>