I have a vector of dates in the following format: YYWW. For example 0951 is year 2009 and week 51 of that year and so on.
What I want is to keep this format and create a new variable that has + 7 weeks from the initial dates. The problem is also that 2009 and 2015 have 53 weeks but 2010 has only 52 weeks. How to to also take care of that effectively?
library("dplyr")
# Create the dataframe
df <- data.frame(date = c("0951", "0952", "1001", "1551"))
df_1 <- df %>%
mutate(get_date = as.Date(paste0(substr(date, 1,2), "-W", substr(date, 3, 4), "-1"), format = "%y-W%U-%u"))
I have tried to convert first the initial format of the week into something I could manipulate and then add 7 weeks on this new variable but for example for 0951 observation when I run the above code it returns next week (i.e. week 52 of 2009) which is wrong but for the “1001” it returns the correct date.
Could someone please help?
Thanks,