title: How to get the cumulative sum by group in R?
body: <p>Suppose I have a dataframe such that:</p>
  
  <pre><code>df&lt;-data.frame(id=1:8,group=c(1,0,0,1,1,0,1,0),rep=c(rep("d1",4),rep("d2",4)),value=rbinom(8,1,0.6))
  df
    id group rep value
  1  1     1  d1     0
  2  2     0  d1     0
  3  3     0  d1     0
  4  4     1  d1     1
  5  5     1  d2     1
  6  6     0  d2     0
  7  7     1  d2     1
  8  8     0  d2     1
  </code></pre>
  
  <p>What's the best way to get the cumulative sum by <code>group</code> and <code>rep</code> such that:</p>
  
  <pre><code>cumsum
  group d1  d1+d2  d1+d2+d3
  0     0     1      ...
  1     1     3      ...
  </code></pre>