title: How to group rows in my data.frame?
body: <p>I have a data.frame like this:</p>
  
  <pre><code>x &lt;- data.frame(names=c('NG_1', 'NG_2', 'FG_1', 'FG_2'), score=c(1,2,3,4), label=c('N','N','F','F'))
  x
    names score label
  1  NG_1     1     N
  2  NG_2     2     N
  3  FG_1     3     F
  4  FG_2     4     F
  </code></pre>
  
  <p>I want to group the two groups (N,F) by doing a substring match. For example, <code>NG_1</code> matches with <code>FG_1</code>. I am looking for my result something like this:</p>
  
  <pre><code>y &lt;- data.frame(name1=c('NG_1','NG_2'), name2=c('FG_1', 'FG_2'),   score1=c(1,2), score2=c(3,4))
  y
    name1 name2 score1 score2
  1  NG_1  FG_1      1      3
  2  NG_2  FG_2      2      4
  </code></pre>
  
  <p>The resulting table doesn't need to look exactly like above, but I do want the scores grouped.</p>
  
  <p>The only way I can think of is to run a for-loop over all rows with the label=<code>N</code> and match each of them to <code>F</code>. Is there anything better?</p>