title: Grep a list of terms, group by and summarise values using dplyr
body: <p>I have a table that looks like this:</p>
  <pre><code>  ID          term value
  1  A cat,dog,snake    10
  2  B       cat,eel    50
  3  C      fish,eel     3
  4  D      fish,dog     6
  
  data.frame(ID = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;),
             term = c(&quot;cat,dog,snake&quot;, &quot;cat,eel&quot;, &quot;fish,eel&quot;, &quot;fish,dog&quot;),
             value = c(10, 50, 3, 6))
  </code></pre>
  <p>I have a list of interest:</p>
  <pre><code>dog
  fish
  eel
  </code></pre>
  <p>What I want to do is grep each row for each item in the list and calculate the mean (value column). Like this:</p>
  <pre><code>  term mean
  1  dog  8.0
  2 fish  4.5
  3  eel 26.5
  </code></pre>
  <p>Where every instance where there is a <code>'dog'</code> it calculates the <code>mean</code> of <code>value</code>.</p>
  <p>Something like this doesn't work:</p>
  <pre><code>df %&gt;% 
    group_by(., grepl(list, term)) %&gt;% 
    summarise(mean = mean(value))
  </code></pre>
  <p>What I don't want to do is separate each term into its own row because some rows of term have 100s of options. So the only efficient way I can think of is to group by a grep search. Though perhaps I am wrong...</p>