Convert fromat YYYY-WW to DD-MM-YYYY

Hi posit community,
I have this dataset and I would like to convert it from YYYY-WW to DD-MM-YYYY in isoweek format.
Every week in each year could be represented as a weekly date (DD-MM-YYYY) as a world consensus. Each year should contain 52 or 53 weeks. Finally, I would like to start every week on Monday.
-The text is apt to be copied and pasted in a csv.

year week Adenovirus
2019 1 16
2019 2 16
2019 3 28
2019 4 11
2019 5 11
2019 6 10
2019 7 7
2019 8 19
2019 9 9
2019 10 16
2019 11 16
2019 12 14
2019 13 22
2019 14 29
2019 15 29
2019 16 25
2019 17 36
2019 18 49
2019 19 29
2019 20 51
2019 21 43
2019 22 57
2019 23 49
2019 24 61
2019 25 49
2019 26 49
2019 27 85
2019 28 61
2019 29 66
2019 30 68
2019 31 69
2019 32 57
2019 33 60
2019 34 43
2019 35 58
2019 36 53
2019 37 42
2019 38 25
2019 39 50
2019 40 40
2019 41 40
2019 42 38
2019 43 32
2019 44 25
2019 45 28
2019 46 14
2019 47 16
2019 48 27
2019 49 19
2019 50 14
2019 51 19
2019 52 20
2020 1 11
2020 2 12
2020 3 17
2020 4 25
2020 5 21
2020 6 16
2020 7 18
2020 8 13
2020 9 16
2020 10 11
2020 11 15
2020 12 29
2020 13 67
2020 14 55
2020 15 37
2020 16 12
2020 17 8
2020 18 8
2020 19 23
2020 20 3
2020 21 4
2020 22 5
2020 23 7
2020 24 7
2020 25 2
2020 26
2020 27 1
2020 28 2
2020 29 2
2020 30 3
2020 31 4
2020 32 7
2020 33 2
2020 34 1
2020 35 1
2020 36 2
2020 37 6
2020 38 1
2020 39 3
2020 40 1
2020 41 4
2020 42 2
2020 43 6
2020 44 2
2020 45 1
2020 46 4
2020 47 2
2020 48 4
2020 49 4
2020 50 3
2020 51 4
2020 52 1
2020 53 3
2021 1 2
2021 2 1
2021 3
2021 4 1
2021 5 1
2021 6 2
2021 7 4
2021 8 3
2021 9
2021 10
2021 11 1
2021 12 5
2021 13 1
2021 14
2021 15 4
2021 16 1
2021 17 3
2021 18 2
2021 19 4
2021 20 3
2021 21 2
2021 22 3
2021 23 5
2021 24 7
2021 25 4
2021 26 3
2021 27
2021 28 5
2021 29 2
2021 30 10
2021 31 8
2021 32 3
2021 33 6
2021 34 8
2021 35 15
2021 36 7
2021 37 7
2021 38 16
2021 39 9
2021 40 22
2021 41 14
2021 42 10
2021 43 6
2021 44 12
2021 45 12
2021 46 14
2021 47 16
2021 48 23
2021 49 16
2021 50 13
2021 51 7
2021 52 20
2022 1 27
2022 2 18
2022 3 18
2022 4 17
2022 5 18
2022 6 16
2022 7 13
2022 8 10
2022 9 8
2022 10 11
2022 11 16
2022 12 23
2022 13 19
2022 14 21
2022 15 27
2022 16 35
2022 17 35
2022 18 44
2022 19 46
2022 20 83
2022 21 59
2022 22 78
2022 23 70
2022 24 97
2022 25 70
2022 26 67
2022 27 68
2022 28 64
2022 29 45
2022 30 43
2022 31 46
2022 32 64
2022 33 76
2022 34 74
2022 35 59
2022 36 62
2022 37 58
2022 38 72
2022 39 83
2022 40 84
2022 41 90
2022 42 98
2022 43 105
2022 44 120
2022 45 104
2022 46 104
2022 47 96
2022 48 110
2022 49 122
2022 50 134
2022 51 137
2022 52 124
2023 1 95
2023 2 107
2023 3 102
2023 4 87
2023 5 79
2023 6 66
2023 7 86
2023 8 73
2023 9 69
2023 10 56
2023 11 68
2023 12 59
2023 13 77
2023 14 123
2023 15 132
2023 16 149
2023 17 192
2023 18 200
2023 19 227
2023 20 248
2023 21 318
2023 22 304
2023 23 335

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

@technocrat , thank you for your time and your response.
:smiley:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.