I have a data.frame where each id maps to several discontiguous linear intervals, which do not overlap, and are sorted in ascending order:
df <- data.frame(id = c(rep("id1",3),rep("id2",4)),
start = c(101,220,307,550,658,742,855),
end = c(154,246,326,625,712,811,944),
stringsAsFactors = F)
I'd like to add new start and end columns that will cumulatively sum up the interval widths and show the cumulative start and end coordinates.
So, for the example df above, these new start and end columns (cum.start, cum.end) will be:
df$cum.start <- c(1,55,82,1,77,132,202)
df$cum.end <- c(54,81,101,76,131,201,291)
Any dplyr way of doing this?