I have DF, with unique ID's and TYPE, and I intend, from an interval between dates (DT_STARD and DT_END), to search and count how many times they appear. This is my DF_1:
ID <- c(111,222,222,333,444,444)
TYPE <- c('A1','A1','B1','B1','A1','B1')
DT_START <- c(as.Date(c('2022/07/20','2022/07/18','2022/07/10','2022/07/05','2022/07/03','2022/07/01') ,"%Y/%m/%d"))
DT_END <- c(as.Date(c('2021/07/20','2021/07/18','2021/07/10','2021/07/05','2021/07/03','2021/07/01') ,"%Y/%m/%d"))
DF_1 <- data.frame(ID,TYPE,DT_START,DT_END)
And I want to look up the date range in that DF_2:
ID <- c(111,111,111,111,222,222,444,444,444)
TYPE <- c('A1','A1','A1','A1','A1','A1','A1','B1','B1')
DT <- c(as.Date(c('2022/06/01','2022/05/15','2022/01/01','2021/06/01','2022/03/02','2021/12/21','2021/12/29','2022/06/30','2022/06/15') ,"%Y/%m/%d"))
DF_2 <- data.frame(ID,TYPE,DT)
And this is the result I want to get:
ID <- c(111,222,222,333,444,444)
TYPE <- c('A1','A1','B1','B1','A1','B1')
DT_START <- c(as.Date(c('2022/07/20','2022/07/18','2022/07/10','2022/07/05','2022/07/03','2022/07/01') ,"%Y/%m/%d"))
DT_END <- c(as.Date(c('2021/07/20','2021/07/18','2021/07/10','2021/07/05','2021/07/03','2021/07/01') ,"%Y/%m/%d"))
COUNT <- c(3,2,0,0,1,2)
DF_3 <- data.frame(ID,TYPE,DT_START,DT_END,COUNT)
How do I look up and count a from a date range?