Someone please explain this:
strptime(c("2010-01", "2010-02"), format="%Y-%W")
[1] "2010-05-21" "2010-05-21"
Why May 21st? I'm expecting the first and second weeks of the year (01) and (02) to be in January... %W is week of the year, isn't it?
ISOweek2date in the ISOweek package works:
library(ISOweek)
ISOweek2date(c("2010-W01-1", "2010-W02-1"))
[1] "2010-01-04" "2010-01-11"
To get the same results as of ISOweek2date, you should give strptime the same level of details in the time string and format as you did for ISOweek2date.
So adding a "-1" for first day in the week in the time string and -%w in the format string gives you the same result as ISOweek2date:
strptime(c("2010-01-1", "2010-02-1"), format="%Y-%W-%w")
#[1] "2010-01-04" "2010-01-11"
As mentioned above, without enough information you get the current date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With