title: Mutate with dplyr using multiple conditions
body: <p>I have a data frame (df) below and I want to add an additional column, <code>result</code>, using dplyr that will take on the value 1 if <code>z == "gone"</code> and where <code>x</code> is the maximum value for group <code>y</code>.</p>
  
  <pre><code>   y  x    z
  1  a  3 gone
  2  a  5 gone
  3  a  8 gone
  4  a  9 gone
  5  a 10 gone
  6  b  1     
  7  b  2     
  8  b  4     
  9  b  6     
  10 b  7     
  </code></pre>
  
  <p>If I were to simply select the maximum for each group it would be:</p>
  
  <pre><code>df %&gt;%
    group_by(y) %&gt;%
    slice(which.max(x))
  </code></pre>
  
  <p>which will return:</p>
  
  <pre><code>   y  x  z
  1  a 10  gone
  2  b  7      
  </code></pre>
  
  <p>This is not what I want. I need to take advantage of the max value of <code>x</code> for each group in <code>y</code> while checking to see if <code>z == "gone"</code>, and if <code>TRUE</code> 1 otherwise 0. This would look like:</p>
  
  <pre><code>   y  x    z result
  1  a  3 gone      0
  2  a  5 gone      0
  3  a  8 gone      0
  4  a  9 gone      0
  5  a 10 gone      1
  6  b  1           0
  7  b  2           0
  8  b  4           0
  9  b  6           0
  10 b  7           0
  </code></pre>
  
  <p>I'm assuming I would use a conditional statement within <code>mutate()</code> but I cannot seem to find an example. Please advise.</p>