I am dealing with individuals who received a particular treatment and I want to know the time ranges they were treated, or within 5 days of ending a treatment and starting another.
r <- read.table(text=”
ID Start_Date End_Date
1 05-06-18 05-10-18
1 05-08-18 05-14-18
1 05-16-18 05-25-18
1 06-28-19 07-02-19
1 07-03-19 07-08-19
2 04-20-18 04-23-18
2 07-20/18 07-25-18
2 07-26-18 07-30-18
3 05-14-17 05-29-17″,
stringsAsFactors=FALSE, header=TRUE)
This is what I had, and this is what I want:
r <- read.table(text=”
ID Start_Date End_Date
1 05-06-18 05-25-18
1 06-28-19 07-08-19
2 04-20-18 07-30-18
3 05-14-17 05-29-17″,
stringsAsFactors=FALSE, header=TRUE)
This is the code I have tried, but doesn’t quite get what I am after./questions/56937633/a-way-to-recode-consecutive-start-and-stop-dates-in-long-format-to-one-vector