The timeDate package has a great function isBizday , which made it more interesting than it seemed at first glance.
date.in <- dmy(c("30-8-2001", "12-1-2003", "28-2-2003", "20-5-2004"))
Here is the function to do the work. It was wise to choose 1:10 for days to look ahead, but this, of course, can be adjusted.
deadline <- function(x) { days <- x + 1:10 Deadline <- days[isBizday(as.timeDate(days))][6] data.frame(DateIn = x, Deadline, DayOfWeek = weekdays(Deadline), TimeDiff = difftime(Deadline, x)) }
And here is the result:
library(timeDate) Reduce(rbind, Map(deadline, as.Date(date.in)))
source share