I have data where I count episodes of care (e.g. ER visits). The trick is that I can’t count on every visit, because sometimes the second or third visit is actually a continuation of the previous problem. Thus, they gave me a direction for counting visits using a 30-day “clean period” or “waiting period”, so I looked for the first event (VISIT 1) by the patient (minimum date), I consider this event, then apply the rules so that NOT Count any visits that occur within 30 days after the first event. After the 30-day window has passed, I can start searching for the second visit (VISIT 2), count it, and then apply the 30-day black color again (not counting the visits that occur 30 days after visit No. 2) .. wash, rinse, repeat ...
I falsified a very messy solution that requires a lot of babysitting and manual step checking (see below). I have to believe that there is a better way. HELP!
data1 <- structure(list(ID = structure(c(2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c("", "patient1", "patient2", "patient3"), class = "factor"), Date = structure(c(14610, 14610, 14627, 14680, 14652, 14660, 14725, 15085, 15086, 14642, 14669, 14732, 14747, 14749), class = "Date"), test = c(1L, 1L, 1L, 2L, 1L, 1L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 2L)), .Names = c("ID", "Date", "test"), class = "data.frame", row.names = c(NA, 14L)) library(doBy)