Skip to content
Prev 366590 / 398502 Next

Match ISO 8601 week-of-year numbers to month-of-year numbers on Windows with German locale

Aye, but this:

  some_dates <- as.POSIXct(c("2015-12-24", "2015-12-31", "2016-01-01",
"2016-01-08"))

  (year_week <- format(some_dates, "%Y-%U"))
  ## [1] "2015-51" "2015-52" "2016-00" "2016-01"

  (year_week_day <- sprintf("%s-1", year_week))
  ## [1] "2015-51-1" "2015-52-1" "2016-00-1" "2016-01-1"

  (as.POSIXct(year_week_day, format = "%Y-%U-%u"))
  ## [1] "2015-12-21 EST" "2015-12-28 EST" "2016-01-04 EST" "2016-01-04 EST"

works fine on macOS & Linux (Ubuntu, anyway), but it fails on Windows
(10, 64bit, R 3.3.2):

  (as.POSIXct(year_week_day, format = "%Y-%U-%u"))
  ## [1] "2015-12-21 PST" "2015-12-28 PST" NA               "2016-01-04 PST"
On 1/12/17, David Winsemius <dwinsemius at comcast.net> wrote: