title: Add a new column of the sum by group
body: <p>Suppose I have a data frame like this:</p>
  
  <pre><code>set.seed(123)
  df &lt;- as.data.frame(cbind(y&lt;-sample(c("A","B","C"),10,T), X&lt;-sample(c(1,2,3),10,T)))
  df &lt;- df[order(df$V1),]
  </code></pre>
  
  <p>Is there a simply function to sum (or any FUN) V2 by V1 and add to df as a new column, such that:</p>
  
  <pre><code>df$sum &lt;- c(6,6,8,8,8,8,6,6,6,6)
  df
  </code></pre>
  
  <p>I may write a function for that, but I have to do that frequently and be better to know the simplest way to realize that.</p>