title: R data.table sum of group subset using dates
body: <p>I have a dataset like the following:</p>
  
  <pre><code>library(data.table)    
  dt1 &lt;- data.table(urn = c(rep("a", 5), rep("b", 4)),
                    amount = c(10, 12, 23, 15, 19, 42, 11, 5, 10),
                    date = as.Date(c("2016-01-01", "2017-01-02", "2017-02-04",
                                     "2017-04-19", "2018-02-11", "2016-02-14",
                                     "2017-05-06", "2017-05-12", "2017-12-12")))
  dt1
  #    urn amount       date
  # 1:   a     10 2016-01-01
  # 2:   a     12 2017-01-02
  # 3:   a     23 2017-02-04
  # 4:   a     15 2017-04-19
  # 5:   a     19 2018-02-11
  # 6:   b     42 2016-02-14
  # 7:   b     11 2017-05-06
  # 8:   b      5 2017-05-12
  # 9:   b     10 2017-12-12
  </code></pre>
  
  <p>I am trying to determine the cumulative value for a group over the preceding 12 months. I know I can use <code>shift</code> with <code>data.table</code> to scan backwards or forwards, the biggest challenge I can't get my head around is how to know how many records to sum when the number can change based on how many records each <code>urn</code> has.</p>
  
  <p>The type of results I am looking for are:</p>
  
  <pre><code>dt1
  #    urn amount       date summed12m
  # 1:   a     10 2016-01-01        10
  # 2:   a     12 2017-01-02        12
  # 3:   a     23 2017-02-04        35
  # 4:   a     15 2017-04-19        50
  # 5:   a     19 2018-02-11        34
  # 6:   b     42 2016-02-14        42
  # 7:   b     11 2017-05-06        11
  # 8:   b      5 2017-05-12        16
  # 9:   b     10 2017-12-12        26   
  </code></pre>
  
  <p>I'm preferably looking for a <code>data.table</code> solution due to the volume of my data, but am open to other options too if it is likely to be efficient over a table with about 12M records.</p>