title: Calculate cumulative sum (cumsum) by group
body: <p>With data frame:</p>
  
  <pre><code>df &lt;- data.frame(id = rep(1:3, each = 5)
                   , hour = rep(1:5, 3)
                   , value = sample(1:15))
  </code></pre>
  
  <p>I want to add a cumulative sum column that matches the <code>id</code>:</p>
  
  <pre><code>df
     id hour value csum
  1   1    1     7    7
  2   1    2     9   16
  3   1    3    15   31
  4   1    4    11   42
  5   1    5    14   56
  6   2    1    10   10
  7   2    2     2   12
  8   2    3     5   17
  9   2    4     6   23
  10  2    5     4   27
  11  3    1     1    1
  12  3    2    13   14
  13  3    3     8   22
  14  3    4     3   25
  15  3    5    12   37
  </code></pre>
  
  <p>How can I do this efficiently? Thanks!</p>