I have the problem that I would like to change a date column that currently has the class"character" to a the class "date". The format here is yyyyww.
You can see a snippet of the dataframe here:
Avsales <- c("4500", "6000", "5500", "5000", "5100")
Week <- c("2003-23", "2003-24", "2003-25", "2003-26", "2003-27")
Data <- data.frame(Avsales, Week)
I know there are already similar questions here on the topic (such as Transform year/week to date object) and I already tried to apply the solution, however I would like to keep the weeks and not make them single days, since it is an average of the sales for the whole week.
For this reason I tried the following solution:
data$week <- as.Dates(data$Week, yyyyww = TRUE)
However, the class remains "character" and not "date".
For that reason I tried several other options with as.Date
like
data$week <- as.Date(data$Week, format = "%Y-%W")
But as I want to have the format "yyyy-ww" it didn't work for me.
Could it be because date always means the specific day and I need a completely different approach for this?
I would be happy if you can help me in this regard. Thanks!