title: R dplyr `group_by` seems not working to create a new value using `case_when`?
body: <p>I am trying to create a new column in data  frame based on the groups <code>site</code> and conditions using <code>case_when</code>. However, my output seems to ignore my groups?</p>
  
  <p>My example: </p>
  
  <pre><code>site     = c("a", "b", "b", "d", "d", "d", "e", "f", "g")
  distance = c("PA", "PA", "5", "PA", "20", "5", "5", "20", "PA")
  df &lt;- data.frame(site, 
                   distance)
  </code></pre>
  
  <p>Apply conditions:</p>
  
  <ul>
  <li>if there is only PA by group        -> PA</li>
  <li>if there is PA and something else   -> unclear</li>
  <li>if there is something else (not PA) -> buffer</li>
  </ul>
  
  <p>Script:</p>
  
  <pre><code>df %&gt;% 
    group_by(site) %&gt;% 
    mutate(source = case_when(distance == "PA" ~ "PA",
                              any(c("PA") %in% distance) ~ "unclear",
                              TRUE ~ "buffer")) 
  </code></pre>
  
  <p>My example seems to work well row-wise, but not taking into account groups?</p>
  
  <p>Expected output by group <code>site</code>:</p>
  
  <pre><code>  site  distance source 
    &lt;fct&gt; &lt;fct&gt;    &lt;chr&gt;  
  1 a     PA       PA     
  2 b     PA       unclear    # not PA
  3 b     5        unclear
  4 d     PA       unclear    # not PA, as the group contains other values! 
  5 d     20       unclear
  6 d     5        unclear
  7 e     5        buffer 
  8 f     20       buffer 
  9 g     PA       PA     
  </code></pre>