title: How to manipulate a data.frame by factor with dplyr
body: <pre><code>df &lt;- data.frame(a=factor(c(1,1,2,2,3,3) ), b=c(1,1, 10,10, 20,20) )
  
    a  b
  1 1  1
  2 1  1
  3 2 10
  4 2 10
  5 3 20
  6 3 20
  </code></pre>
  
  <p>I want to split the data frame by column a, calculate b/sum(b) in each group, and put the result in column c. With plyr I can do:</p>
  
  <pre><code>fun &lt;- function(x){
    x$c=x$b/sum(x$b)
    x
  } 
  ddply(df, .(a), fun )
  </code></pre>
  
  <p>and have</p>
  
  <pre><code>  a  b   c
  1 1  1 0.5
  2 1  1 0.5
  3 2 10 0.5
  4 2 10 0.5
  5 3 20 0.5
  6 3 20 0.5
  </code></pre>
  
  <p>but how can I do it with dplyr? </p>
  
  <pre><code>df %.% group_by(a) %.% do(fun)
  </code></pre>
  
  <p>returns a list instead of a data.frame.</p>