r - Adding 15 business days in lubridate -



r - Adding 15 business days in lubridate -

i have long list of start dates of procedure. rules require procedure completed in, @ most, 6 business days. wish compute deadline.

using lubridate in r, can six-day deadline thus

> library(lubridate) > date.in <- dmy(c("30-8-2001", "12-1-2003", "28-2-2003", "20-5-2004")) > date.in [1] "2001-08-30 utc" "2003-01-12 utc" "2003-02-28 utc" "2004-05-20 utc" > deadline.using.days <- date.in + days(6) > deadline.using.days [1] "2001-09-05 utc" "2003-01-18 utc" "2003-03-06 utc" "2004-05-26 utc"

is there easy way add together 6 business days --- i.e., skipping saturdays , sundays? give thanks you.

there's nifty function isbizday in timedate bundle made more fun seemed on first glance.

date.in <- dmy(c("30-8-2001", "12-1-2003", "28-2-2003", "20-5-2004"))

here's function work. seemed reasonable take 1:10 days ahead, can adjusted of course.

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's result:

library(timedate) reduce(rbind, map(deadline, as.date(date.in))) # datein deadline dayofweek timediff # 1 2001-08-30 2001-09-07 fri 8 days # 2 2003-01-12 2003-01-20 mon 8 days # 3 2003-02-28 2003-03-10 mon 10 days # 4 2004-05-20 2004-05-28 fri 8 days

r lubridate

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -