I have a string of date characters in Year-week format as such:
weeks.strings <- c("2002-26", "2002-27", "2002-28", "2002-29", "2002-30", "2002-31")
However, converting this character to the Date class results in the loss of the week identifier:
> as.Date(weeks.strings, format="%Y-%U")
[1] "2002-08-28" "2002-08-28" "2002-08-28" "2002-08-28" "2002-08-28"
[6] "2002-08-28"
As shown above, the format is converted to year-concatenated with today's date, so all information about the original week is lost (for example, using the format function or strptime to try to return to the original format.
One solution that I found in the help group is specifying the day of the week:
as.Date(weeks.strings, format="%Y-%u %U")
[1] "2002-02-12" "2002-02-19" "2002-02-26" "2002-03-05" "2002-01-02"
[6] "2002-01-09"
But it seems that this leads to incorrect page numbering (does not match the original line).
Any guidance would be appreciated.
source
share