title: R - dplyr - mutate_if multiple conditions
body: <p>I want to mutate a column based on multiple conditions. For example, for each column where the max is 5 and the column name contains "xy", apply a function.</p>
  
  <pre><code>df &lt;- data.frame(
    xx1 = c(0, 1, 2),
    xy1 = c(0, 5, 10),
    xx2 = c(0, 1, 2),
    xy2 = c(0, 5, 10)
  )
  &gt; df
  
  xx1 xy1 xx2 xy2
  1   0   0   0   0
  2   1   5   1   5
  3   2  10   2  10
  
  df2 &lt;- df %&gt;% mutate_if(~max(.)==10, as.character)
  &gt; str(df2)
  'data.frame':   3 obs. of  4 variables:
   $ xx1: num  0 1 2
   $ xy1: chr  "0" "5" "10"
   $ xx2: num  0 1 2
   $ xy2: chr  "0" "5" "10"
  #function worked
  df3 &lt;- df %&gt;% mutate_if(str_detect(colnames(.), "xy"), as.character)
  &gt; str(df3)
  'data.frame':   3 obs. of  4 variables:
   $ xx1: num  0 1 2
   $ xy1: chr  "0" "5" "10"
   $ xx2: num  0 1 2
   $ xy2: chr  "0" "5" "10"
  #Worked again
  </code></pre>
  
  <p>Now when I try to combine them</p>
  
  <pre><code>df4 &lt;- df %&gt;% mutate_if((~max(.)==10) &amp; (str_detect(colnames(.), "xy")), as.character)
  </code></pre>
  
  <blockquote>
    <p>Error in (~max(.) == 10) &amp; (str_detect(colnames(.), "xy")) : 
      operations are possible only for numeric, logical or complex types</p>
  </blockquote>
  
  <p>What am I missing?</p>