-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
Description
dates = structure(0:7, class = 'Date')
dates
# [1] "1970-01-01" "1970-01-02" "1970-01-03"
# [4] "1970-01-04" "1970-01-05" "1970-01-06"
# [7] "1970-01-07" "1970-01-08"
I think we'd expect week(dates)
to be 1L
for the first seven days, but this is not the case:
week(dates)
# [1] 1 1 1 1 1 1 2 2
The fix is trivial -- the problem is yday
returns 1
-based days, but relying on %/%
needs 0
-based days:
week = function(x) (yday(x) - 1L) %/% 7L + 1L
# -or better, given what yday does-
week = function(x) as.POSIXlt(x)$yday %/% 7L + 1L
Just want to make sure this is not expected behavior? And if this is expected, we should document.