title: Using conditions in dplyr::mutate
body: <p>I am working with a large data frame. I'm trying to create a new vector based on the conditions that exist in two current vectors. </p>
  
  <p>Given the size of the dataset (and its general awesomeness) I'm trying to find a solution using dplyr, which has lead me to mutate. I feel like I'm not far off, but I'm just not able to get a solution to stick.</p>
  
  <p>My data frame resembles:</p>
  
  <pre><code>   ID  X  Y
  1   1 10 12
  2   2 10 NA
  3   3 11 NA
  4   4 10 12
  5   5 11 NA
  6   6 NA NA
  7   7 NA NA
  8   8 11 NA
  9   9 10 12
  10 10 11 NA
  </code></pre>
  
  <p>To recreate it:</p>
  
  <pre><code>ID &lt;- c(1:10)
  X &lt;- c(10, 10, 11, 10, 11, NA, NA, 11, 10, 11)
  Y &lt;- c(12, NA, NA, 12, NA, NA, NA, NA, 12, NA)
  </code></pre>
  
  <p>I'm looking to create a new vector 'Z' from the existing data. If Y > X, then I want it return the value from Y. If Y is NA then I'd like it to return the X value. If both are NA, then it should return NA.</p>
  
  <p>My attempt thus far, has using the code below has let me create a new vector meeting the first condition, but not the second. </p>
  
  <pre><code>newData &lt;- data %&gt;% 
          mutate(Z =
                 ifelse(Y &gt; X, Y,
                 ifelse(is.na(Y), X, NA)))
  
  &gt; newData
     ID  X  Y  Z
  1   1 10 12 12
  2   2 10 NA NA
  3   3 11 NA NA
  4   4 10 12 12
  5   5 11 NA NA
  6   6 NA NA NA
  7   7 NA NA NA
  8   8 11 NA NA
  9   9 10 12 12
  10 10 11 NA NA
  </code></pre>
  
  <p>I feel like I'm missing something mindblowingly simple. Can point me in the right direction?</p>