0
IT_tickets[,"ticket_age"] <- NA
{R aging_count for Tasks}
IT_tickets$ticket_age[c(all_tasks)] <- difftime(IT_tickets$closed_at_date[c(all_tasks)], IT_tickets$sys_created_date[c(all_tasks)], units = "days")

I have this column called "ticket age" in my dataset IT_tickets, which calculates the difference in days when a ticket gets created and closed. How can I recode this so that it excludes weekends from the difference in days.

Similar to how NETWORK days function works in Excel.

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

If you don't have to include the holidays, you can do this

IT_tickets$ticket_age[c(all_tasks)] <- sum(!weekdays(seq(IT_tickets$sys_created_date[c(all_tasks)],
                                                                IT_tickets$closed_at_date[c(all_tasks)], 
                                                                "days")) %in% c("Saturday", "Sunday")) - 1 

If you want to include the start date into the count, you can remove the subtraction of 1.

Another way:

IT_tickets$ticket_age[c(all_tasks)] <- (IT_tickets$ticket_age[c(all_tasks)]%/%7) * 5 + IT_tickets$ticket_age[c(all_tasks)]%%7
Mohanasundaram
  • 2,889
  • 1
  • 8
  • 18