title: How to aggregate based on condition?
body: <p>I'm learning R. I would aggregate data which looks like this:</p>
  
  <pre><code>ID   Score  Elements
  231  123    "a,b,c"
  132  123    "b,c,d"
  321  123    "e"
  645  123    "d, f"
  321  200    "foo,bar,baz"
  </code></pre>
  
  <p><strong>I would like to combine all rows where an element matches.</strong> The above would result in 3 rows with only the rows 1,2,3 combining because of a shared b/c and d. It's possible to have hundreds of rows which must be combined, or identical rows.</p>
  
  <p>Output should be:</p>
  
  <pre><code>Score  Elements
  123    "a,b,c,d,f"
  123    "e"
  200    "foo,bar,baz"
  </code></pre>
  
  <p>I'm currently using <code>aggregate</code> on the Score column because this is <em>almost</em> a good group identifier, however in some corner cases there are groups with the same score ('e' in the above). I'm using a custom combiner function to combine the Score values into string vectors. My current code is:</p>
  
  <pre><code>customCombiner &lt;- function(foo) {
      return(unique(unlist(strsplit(paste(as.vector(foo), collapse = ","),','))))
  }
  result = aggregate(
      myDataFrame$Elements,
      by=list(score=myDataFrame$score),
      customCombiner
  )
  </code></pre>
  
  <p>Is it possible to aggregate rows but first check if they should be aggregated? Or a different solution to my problem?</p>