Welcome to the community!
I haven't used MMWRweek
package before, but it seems to work:
MMWRweek::MMWRweek2Date(MMWRyear = 2015,
MMWRweek = 36,
MMWRday = 3)
#> [1] "2015-09-08"
It of course follows the convention mentioned in the documentation:
The first day of any MMWR week is Sunday. MMWR week numbering is sequential beginning with 1 and incrementing with each week to a maximum of 52 or 53. MMWR week #1 of an MMWR year is the first week of the year that has at least four days in the calendar year. For example, if January 1 occurs on a Sunday, Monday, Tuesday or Wednesday, the calendar week that includes January 1 would be MMWR week #1. If January 1 occurs on a Thursday, Friday, or Saturday, the calendar week that includes January 1 would be the last MMWR week of the previous year (#52 or #53). Because of this rule, December 29, 30, and 31 could potentially fall into MMWR week #1 of the following MMWR year.
I think you're experiencing the issue with as.Date
because the way R counts the week numbers.
Here's from the documentation of strptime
:
%u
Weekday as a decimal number (1–7, Monday is 1).
%U
Week of the year as decimal number (00–53) using Sunday as the first day 1 of the week (and typically with the first Sunday of the year as day 1 of week 1). The US convention.
Check this:
as.Date(x = "2019-1-1",
format = "%Y-%U-%u")
#> [1] "2019-01-07"
Created on 2019-03-28 by the reprex package (v0.2.1)
I'm adding an excerpt from this SO post:
Week of the year
-
US convention : Week of the year as decimal number (00–53) using Sunday as the first day 1 of the week (and typically with the first Sunday of the year as day 1 of week 1):
%U
-
UK convention : Week of the year as decimal number (00–53) using Monday as the first day of week (and typically with the first Monday of the year as day 1 of week 1):
%W
-
ISO 8601 definition : Week of the year as decimal number (01–53) as defined in ISO 8601. If the week (starting on Monday) containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1:
%V
which is accepted but ignored on input.
Note that there is also a week-based year ( %G
and %g
) which is to be used with %V
as it may differ from the calendar year ( %Y
and %y
).
Numeric weekday
- Weekday as a decimal number (1–7, Monday is 1):
%u
- Weekday as decimal number (0–6, Sunday is 0):
%w
- Interestingly, there is no format for the case Sunday is counted as day 1 of the week.
Hope this helps.