title: Mutate variable if certain columns contain string in R
body: <p>I have been struggling for hours with this dataset. I have searched for hours and tried many things, but I failed (I am a novice in R). So I really hope you guys can help me.</p>
  <p>I have this dataset:</p>
  <pre><code>      df &lt;- data.frame(ID = c(1,2,3,4,5), a.1 = c(&quot;A&quot;, &quot;C&quot;, &quot;C&quot;, &quot;B&quot;,&quot;D&quot;), a.2 = c(&quot;C&quot;, &quot;C&quot;, &quot;D&quot;, &quot;A&quot;,&quot;B&quot;), b.1 = c(&quot;D&quot;, &quot;C&quot;, &quot;A&quot;, &quot;B&quot;,&quot;D&quot;), b.2 = c(&quot;D&quot;, &quot;B&quot;, &quot;C&quot;, &quot;A&quot;,&quot;A&quot;))
      
    ID a.1 a.2 b.1 b.2
  1  1   A   C   D   D
  2  2   C   C   C   B
  3  3   C   D   A   C
  4  4   B   A   B   A
  5  5   D   B   D   A
  </code></pre>
  <p>I would like to mutate a new variable called &quot;result&quot; to be:</p>
  <ul>
  <li>&quot;1&quot; if one of the columns with prefix &quot;a.&quot; contain &quot;A&quot; or &quot;B&quot;</li>
  <li>&quot;0&quot;  if one of the columns with prefix &quot;a.&quot; do not contain &quot;A&quot; or &quot;B&quot;</li>
  </ul>
  <p>So I would get the following result:</p>
  <pre><code>  ID a.1 a.2 b.1 b.2 result
  1  1   A   C   D   D      1
  2  2   C   C   C   B      0
  3  3   C   D   A   C      0
  4  4   B   A   B   A      1
  5  5   D   B   D   A      1
  </code></pre>
  <p>In my real dataset I have 100 variables with prefix &quot;a.&quot;, so I cannot select the columns individually.</p>
  <p>Hopefully you guys can help me!</p>
  <p>Thank you very much!</p>