I\'m trying to write an R function to calculate the number of weekdays between two dates. For example, Nweekdays(\'01/30/2011\',\'02/04/2011\') would equal 5.
Simila
Working this out using lubridate you can create a function like:
library(lubridate)
WorkingDays_function <- function(StartDate,EndDate){
startDate <- dmy(StartDate)
endDate <- dmy(EndDate)
#Now build a sequence between the dates:
myDates <-seq(from = startDate, to = endDate, by = "days")
#Week starts on Sunday (1) so to exclude Sun (1) and Sat (7)
#use > 1 & < 7
working_days <- sum(wday(myDates)>1 & wday(myDates)<7)
print(working_days)
}
WorkingDays_function("11/07/2019","20/07/2019")