title: Using dplyr to group_by and conditionally mutate a dataframe by group
body: <p>I'd like to use dplyr functions to group_by and conditionally mutate a df. Given this sample data:</p>
  
  <pre><code>A   B   C   D
  1   1   1   0.25
  1   1   2   0
  1   2   1   0.5
  1   2   2   0
  1   3   1   0.75
  1   3   2   0.25
  2   1   1   0
  2   1   2   0.5
  2   2   1   0
  2   2   2   0
  2   3   1   0
  2   3   2   0
  3   1   1   0.5
  3   1   2   0
  3   2   1   0.25
  3   2   2   1
  3   3   1   0
  3   3   2   0.75
  </code></pre>
  
  <p>I want to use new column E to categorize A by whether B == 1, C == 2, and D > 0. For each unique value of A for which all of these conditions hold true, then E = 1, else E = 0. So, the output should look like this:</p>
  
  <pre><code>A   B   C   D    E
  1   1   1   0.25 0
  1   1   2   0    0
  1   2   1   0.5  0
  1   2   2   0    0
  1   3   1   0.75 0
  1   3   2   0.25 0
  2   1   1   0    1
  2   1   2   0.5  1
  2   2   1   0    1
  2   2   2   0    1
  2   3   1   0    1
  2   3   2   0    1
  3   1   1   0.5  0
  3   1   2   0    0
  3   2   1   0.25 0
  3   2   2   1    0
  3   3   1   0    0
  3   3   2   0.75 0
  </code></pre>
  
  <p>I initially tried this code but the conditionals don't seem to be working right:</p>
  
  <pre><code> foo$E &lt;- foo %&gt;% 
      group_by(A) %&gt;% 
      mutate(E = {if (B == 1 &amp; C == 2 &amp; D &gt; 0) 1 else 0})
  </code></pre>
  
  <p>Any insights appreciated. Thanks!</p>