title: Group variables in a dataframe R using a specific list
body: <p>I have the following lists:</p>
  
  <pre><code>  group1&lt;-c("A", "B", "D")
    group2&lt;-c("C", "E")
    group3&lt;-c("F")
  </code></pre>
  
  <p>and a dataframe with values and corresponding names:</p>
  
  <pre><code>  df &lt;- data.frame (name=c("A","B","C","D","E","F"),value=c(1,2,3,4,5,6))
    df
      name value
    1    A     1
    2    B     2
    3    C     3
    4    D     4
    5    E     5
    6    F     6
  </code></pre>
  
  <p>I'd like to group the data based on the lists, using the name column;</p>
  
  <pre><code>  df
      name value    group
    1    A     1   group1
    2    B     2   group1
    3    C     3   group2
    4    D     4   group1
    5    E     5   group2
    6    F     6   group3
  </code></pre>
  
  <p>and sum the values for each group.</p>
  
  <pre><code>  df
         group sum
    1   group1   7
    2   group2   8
    3   group3   6
  </code></pre>
  
  <p>I've searched for similar posts, but failed using them for my problem.</p>