I want to determine the month based on the year and the week number. This problem is unique because it's missing the day of week information needed in these examples Transform year/week to date object, Convert week number to date.
year <- c("2017", "2017", "2018")
week <- c("37", "53", "01")
month <- lubridate::month(as.Date(paste0(year, "-", week), format = "%Y-%V"))
> month
[1] 9 9 9
For some reason this returns 9
for each element in my vector. September is the correct month for the first observation, but this cannot be the case for the remaining two.
Expected output:
> month
[1] 9 12 1
Edit: It turns out that this task is unlikely to be solved without knowing the day of week. I'll try to find a workaround to the year/date to avoid this problem altogether.