Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DaysToMatch <- as.Date(c("1991-03-30", "1993-12-18"))
- countDays <- function(initialdate, enddate, DaysToMatch) {
- measurementwindow <- seq(as.Date(initialdate), as.Date(enddate), by="days")
- commonDays <- length(intersect(measurementwindow, DaysToMatch))
- #Or sum(DaysToMatch %in% measurementwindow)
- return(commonDays)
- }
- df$commonDays <- mapply(countDays, df$initialdate, df$enddate,
- MoreArgs = list(DaysToMatch = DaysToMatch))
- df
- # individual initialdate enddate RGR commonDays
- #1 1 1990-03-01 1991-08-05 0.25 1
- #2 2 1991-05-07 1993-02-17 0.30 0
- #3 3 1992-05-02 1995-06-22 0.09 1
- #4 4 1994-03-02 1995-09-12 0.48 0
- #5 5 1995-03-08 1997-08-18 0.34 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement