I want to consolidate the observations into continuous (no gaps in days covered) date ranges. each patid may have multiple ranges in the resulting data frame.I know it can be done with loop.But, is there an effective way to handle this task? Notice that the time interval is not overlapping here and the start_date is increasing.
data is here( i use R:dput, you can copy and assign to your object in R):
structure(list(patid = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L), start_date = structure(c(1L, 2L, 3L, 4L, 5L,
1L, 2L, 3L, 8L, 9L, 6L, 7L, 10L), .Label = c("1/1/2010", "2/1/2010",
"3/1/2010", "4/1/2010", "5/1/2010", "5/6/2011", "7/1/2012", "8/1/2010",
"9/1/2010", "9/1/2012"), class = "factor"), end_date = structure(c(1L,
3L, 4L, 5L, 6L, 1L, 3L, 4L, 8L, 10L, 7L, 9L, 2L), .Label = c("1/31/2010",
"12/1/2012", "2/28/2010", "3/31/2010", "4/30/2010", "5/31/2010",
"6/15/2011", "8/31/2010", "8/31/2012", "9/30/2010"), class = "factor")), class = "data.frame", row.names = c(NA,
-13L))