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
The wday
in both lubridate
and data.table
(yes, data.table
has pretty much everything but the kitchen sink :-) both do a variation on:
as.POSIXlt(x, tz = tz(x))$wday + 1 # lubridate
as.POSIXlt(x)$wday + 1L # data.table
So you could, in theory, just do:
as.POSIXlt("2014-10-18")$wday + 1
## [1] 7
and then test for the weekend days as other answer(s) do.