The task of calculating the difference in dates on business days, i.e. exclude weekends, such as the network days function in Excel.
Here are my details.
e <- structure(list(date.pr = structure(c(15909, 15933, 16517, 15961, 15974, 15978), class = "Date"), date.po = structure(c(15909, 15933, 15954, 15961, 15974, 15978), class = "Date")), .Names = c("date.1", "date.2"), class = c("tbl_df", "data.frame"), row.names = c(NA, -6L))
Found the bizdays package for this task. Which is great for this.
> bizdays(e$date.2,e$date.1) [1] 0 0 563 0 0 0
But my data contains cases where date 2 is before date .1.
e2 <- structure(list(date.pr = structure(c(15909, 15933, 16517, 15961, 5974, 15978, 15978), class = "Date"), date.po = structure(c(15909, 15933, 15954, 15961, 15974, 15978, 15979), class = "Date")), .Names = c("date.1", "date.2"), class = c("tbl_df", "data.frame"), row.names = c(NA, -7L))
Now it gives the following error:
> cal <- Calendar(holidaysANBIMA, weekdays=c("saturday","sunday")) > bizdays(e2$date.2,e2$date.1,cal) Error in bizdays.Date(e2$date.2, e2$date.1, cal) : All from dates must be greater than all to dates.
I think using ifelse () logic, but it gives me the same error.
> ifelse(e2$date.2 < e2$date.1, NA, bizdays(e2$date.2,e2$date.1,cal)) Error in bizdays.Date(e2$date.2, e2$date.1, cal) : All from dates must be greater than all to dates.
Help evaluate.