I have a data frame where each row is a record with its id, start and end dates. I would like to create another data frame that contains every calendar month's start dates (eg "2020-01-01" is January), and a second column counting how many unique records are open (for any/all portion of) that month.
I could create new columns for each calendar month and generate dummies for whether a record is open that month, then add up each column. What's a more efficient way of doing this?
ds <- data.frame(record_id = c("00a", "00b", "00c"),
record_start_date = as.Date(c("2020-01-16", "2020-03-25", "2020-02-22")),
record_end_date = as.Date(c("2020-12-05", "2020-06-21", "2020-11-12")))
tidyr::complete
function