I would like to create a vector from one date to another displayed as YYYYWW which increments by week. It is important that the weeks are displayed in ISO-8601 standard format, here is a link for reference to the ISO-8601: https://www.epochconverter.com/weeks/2021
To my knowledge, the neatest way to generate weeks in this format is by using lubridates isoyear and isoweek. For example:
from_date <- paste0(lubridate::isoyear("2020-01-01"),lubridate::isoweek("2021-01-01"))
> from_date
> "202053"
to_date <- paste0(lubridate::isoyear(Sys.Date()),lubridate::isoweek(Sys.Date()))
> to_date
> "20222"
How can I create an array between from_date and to_date with an increment of one week keeping the ISO-8601 standard?
I have tried something like
YearWeek <- seq(from_date, to_date, by = "weeks")
but seq takes date classes in this instance which forces me out of the ISO-8601 standard. For reference I would like my final result to look like this:
# Vector of YearWeek from 2021-01-01 to todays date incrmented by week
> YearWeek
> [1] 202053 202101 202102 202103 202104 202105 202106 202107 202108 202109 202110 202111 202112 202113 202114
[16] 202115 202116 202117 202118 202119 202120 202121 202122 202123 202124 202125 202126 202127 202128 202129
[31] 202130 202131 202132 202133 202134 202135 202136 202137 202138 202139 202140 202141 202142 202143 202144
[46] 202145 202146 202147 202148 202149 202150 202151 202152 202201