I thought I had understood how I can use as.Date()
but I get an unexpected result when using the UK convention for counting weeks in a given year (%W
).
I have a year-week combination and want to find the date corresponding to Monday and Sunday of that week (if they exist, so it's fine that NA
is returned if the week does not contain Mon or Sun). In the UK week counting, the week starts with a Monday. So to find the Monday of, say, week 1 in 2016, I use the following code, which returns the correct result (4 Jan 2016):
as.Date("2016011", format = "%Y%W%u")
To find the Sunday of that week, I change the last number to 7 because %u
takes 1 to be Monday and 7 to be Sunday (I have also used %w
instead with its definition of Sunday 0 and Monday 1 but with the same result):
as.Date("2016017", format = "%Y%W%u")
My expected output is 10 Jan 2016 but I get 3 Jan 2016. So it seems that as.Date()
treats the week as beginning with Sunday. This however contradicts the definition of %W
.
Any ideas what I'm missing? Thanks!