Hello,
I have an issue to get the the date from a field like 'YYYY - CWxx' for the first week of 2024. I see that 2023 has only 52 weeks and I'm guessing that is creating the issue.
If you can see from the results of my code on the calendar week '2024 - CW01' the date assigned is '2024-01-08'; I would expect and I need instead the date '2024-01-01'.
Below my code:
sample <- data.frame(service_type = c("A","B","C","A","B","C","A","B","C"),
qty = c(38,185,87,29,12,133,2,14,31),
dat_cal_week_id = c("202352","202352","202352","202401","202401","202401","202402","202402","202402"),
week = c("CW52","CW52","CW52","CW01","CW01","CW01","CW02","CW02","CW02")
)
sample$year_week <- paste(substr(as.character(sample$dat_cal_week_id),1,4) ,'-', sample$week)
sample <- data.frame(service_type = c("A","B","C","A","B","C","A","B","C"),
qty = c(38,185,87,29,12,133,2,14,31),
dat_cal_week_id = c("202352","202352","202352","202401","202401","202401","202402","202402","202402"),
week = c("CW52","CW52","CW52","CW01","CW01","CW01","CW02","CW02","CW02")
)
sample$year_week <- paste(substr(as.character(sample$dat_cal_week_id),1,4) ,'-', sample$week)