Convert fromat YYYY-WW to DD-MM-YYYY

Using ISO week convention

# Load the required package
library(ISOweek)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

# Define the start date (January 1, 2019)
start_date <- ISOweek2date("2019-W01-1")

# Define the end date (start of the 23rd ISO week of 2023)
end_date <- ISOweek2date("2023-W23-1")

# Create a sequence of POSIX date objects
the_dates <- seq(start_date, end_date, by = "week")

d <- data.frame(the_date = the_dates)
d$the_year <- year(d$the_date)
d$the_week <- isoweek(d$the_date)
d$the_dow  <- wday(d$the_date,label = TRUE)
d$faked   <- sample(10:30,dim(d)[1],replace = TRUE)
head(d)
#>     the_date the_year the_week the_dow faked
#> 1 2018-12-31     2018        1     Mon    12
#> 2 2019-01-07     2019        2     Mon    24
#> 3 2019-01-14     2019        3     Mon    17
#> 4 2019-01-21     2019        4     Mon    22
#> 5 2019-01-28     2019        5     Mon    10
#> 6 2019-02-04     2019        6     Mon    25

Created on 2023-06-20 with reprex v2.0.2

2 Likes