title: Create cumulative time data for a group
body: <p>I have a dataframe with ID's, event dates, dates. </p>
  
  <pre><code>timeyrs = endate - startdate
  
  eventyr = eventdate - startdate
  </code></pre>
  
  <p>NB: I have rounded these numbers. </p>
  
  <p><code>df1</code></p>
  
  <pre><code>ID  eventdate   startdate   enddate     timeyrs eventyr
  1   20-10-2007  16-06-2003  21-07-2017  14.1  4.34
  1   11-11-08    16-06-2003  21-07-2017  14.1  5.41
  1   26-09-2012  16-06-2003  21-07-2017  14.1  9.28
  2   11-05-2014  20-04-2012  16-06-2017  5.2   2.06
  3   11-04-2017  6-02-2015   21-04-2017  2.2   2.18
  </code></pre>
  
  <p>I would like to summarise the data for the whole dataset into years of follow up data. ie, 1 row for each year (approx 20 years). </p>
  
  <p><code>df2</code> to create:</p>
  
  <pre><code>Year cmltime cmlevent
  1   3   0
  2   3   0
  3   2.2 2
  4   2   0
  5   2   1
  6   1.2 1
  7   1   0
  8   1   0
  9   1   0
  10  1   1
  11  1   0
  12  1   0
  13  1   0
  14  1   0
  15  0.1 0
  </code></pre>
  
  <p>For cumulative time - this is the amount of data available for that year eg. for the first year, there are 3 ID's that contribute a full year worth of data and finally only 1 year of dat for years 6-14. </p>
  
  <p>For cumulative event, this is the sum of the vents that occur in that follow up year. eg. ID"s 2 and 3 had events in the 3rd year of their data. </p>
  
  <p>I have been trialling code from dplyr for this with no luck so far. Suggestions welcome!</p>