Create index for this condition using data.table in R : how to get the startdate and enddate(cumulative) from days

          Variable A  days  stardate  enddate(cumulative) 
              A        2       0           2
              A        3       2           5
              B        4       5           9
              A        3       9          12
              B        8      12          20
              