I am attempting to write a function that counts the number of holidays a person worked in my organization between their start and term date in the year 2017. My organization recognized 6 holidays that year-
New Years Day- 2017-01-02
Memorial Day- 2017-05-29
Independence Day - 2017-07-04
Labor Day - 2017-09-04
Thanksgiving Day- 2017-11-23
Christmas day - 2017-12-25
I used lubridate to combine my year-month-day columns into complete dates using lubridate and dyplr like so:
dates<- data %>% mutate("Term Date" = make_date(month = `Term Month`,
day = data$`Term Day`,
year =data$`Term Year`),
"Start Date"= make_date(month = data$`Start Month`,
day = data$`Start Day`,
year = data$`Start Year`))
I then went on to attempt to write my function.
holidays <- function(x){
z<- 0
if( ymd("2017-01-01") %within% interval(dates$`Start Date`, dates$`Term Date`)){
z <- z + 1
}
print(z)
}
This was only my first step. My goal was to first make my function work for new years and then continue to build in other holidays step by step using if statements.I was unable to get the apply function to work correctly and am unsure if my function even works. I attempted to apply the function like so :
apply(dates,2,holidays)
But got an error argument.
Does anyone have any advice?