I have a vector of date objects (yyyy-mm-dd
) and I want to determine if any of them are on weekend or not. Is there a function that can determine this straighta
You could use isWeekend
from package timeDate. Hard to do more straightforward :). wday
specify which days should be considered as weekdays. By default from Mondays to Fridays.
> today <- isWeekend(Sys.Date(), wday = 1:5)
if (as.logical(today)){
print("YES")
} else print("NO")
From the documentation :
## Dates in April, currentYear:
currentYear = getRmetricsOptions("currentYear")
tS = timeSequence(
from = paste(currentYear, "-03-01", sep = ""),
to = paste(currentYear, "-04-30", sep = ""))
tS
## Subset of Weekends:
isWeekend(tS)
tS[isWeekend(tS)]
It works also with isWeekday
.