title: dplyr conditional sum of columns containing specific value
body: <p>I have faced a problem of mutating the conditional calculation of specific columns, containing specific values.
  The algorythm I want to code is: if condition1=x, calculate the number of columns that contain &quot;a&quot; among columns with &quot;bbb&quot; in the title , if condition1=y, calculate the number of columns that contain &quot;c&quot; among columns with &quot;ddd&quot; in the title.
  As an example, I give the following:</p>
  <pre><code>require(&quot;tidyverse&quot;)
  iris %&gt;% 
    mutate_all(as.character) %&gt;% 
    select(Species, everything()) %&gt;% 
    rowwise() %&gt;% 
    mutate(cat1=case_when(Species==&quot;virginica&quot;~sum(select(., contains(&quot;sepal&quot;), endsWith(&quot;5&quot;))),
                          Species==&quot;versicolor&quot;~sum(select(., contains(&quot;sepal&quot;), startsWith(&quot;6&quot;))),
                          TRUE~&quot;not tested&quot;))
  </code></pre>
  <p>Could you please give me your advices?
  Thank you all in advance.</p>