diff --git a/404.html b/404.html new file mode 100644 index 0000000..0c6a7e8 --- /dev/null +++ b/404.html @@ -0,0 +1,147 @@ + + +
+ + + + +YEAR: 2023 +COPYRIGHT HOLDER: CSIDS ++ +
cstime
provides date time functions for public health purposes.
The core functionality is consistent time conversion between :
+It also provides functions to generate rolling dates for computing the weekly, bi-weekly, 4 week averages.
+cstime
is part of the csverse package suite.
To convert a date to isoyear:
+
+date_to_isoyear_c('2021-01-01')
+#> [1] "2020"
To convert a isoyearweek string to isoyear/isoweek:
+
+isoyearweek_to_isoyear_c("2021-02")
+#> [1] "2021"
+isoyearweek_to_isoweek_c("2021-02")
+#> [1] "02"
To convert a season week to isoweek (and reverse):
+
+seasonweek_to_isoweek_n(10)
+#> [1] 10
+isoweek_to_seasonweek_n(1)
+#> [1] 24
vignettes/date_conversion.Rmd
+ date_conversion.Rmd
We create the following functions to make it easier to work with date and times in different formats.
+For the input, we allow either a numeric (3) or string (“03”, “2020-03”).
+For the output, the user need to specify whether numeric or string is required. Functions end with c
returns a character output and n
returns a double.
By default the functions returns the isoyear or isoweek of today.
+
+date_to_isoyear_c()
+#> [1] "2023"
+date_to_isoyear_n()
+#> [1] 2023
+date_to_isoweek_c()
+#> [1] "49"
+date_to_isoweek_n()
+#> [1] 49
+# provide a date
+date_to_isoyear_c('2021-01-01')
+#> [1] "2020"
+date_to_isoyear_n('2021-01-01')
+#> [1] 2020
+date_to_isoweek_c('2021-01-01')
+#> [1] "53"
+date_to_isoweek_n('2021-01-01')
+#> [1] 53
+date_to_isoyearweek_c('2021-08-11')
+#> [1] "2021-32"
isoyearweek
string
+
+isoyearweek_to_isoyear_c("2021-02")
+#> [1] "2021"
+isoyearweek_to_isoyear_n("2021-02")
+#> [1] 2021
+isoyearweek_to_isoweek_c("2021-02")
+#> [1] "02"
+isoyearweek_to_isoweek_n("2021-02")
+#> [1] 2
A list of isoyearweek
can be accessed in the following way.
+yrwk_19_20 <- dates_by_isoyearweek[isoyear %in% c(2019, 2020)]
+head(yrwk_19_20)
+#> isoyear isoyearweek mon tue wed thu fri
+#> 1: 2019 2019-01 2018-12-31 2019-01-01 2019-01-02 2019-01-03 2019-01-04
+#> 2: 2019 2019-02 2019-01-07 2019-01-08 2019-01-09 2019-01-10 2019-01-11
+#> 3: 2019 2019-03 2019-01-14 2019-01-15 2019-01-16 2019-01-17 2019-01-18
+#> 4: 2019 2019-04 2019-01-21 2019-01-22 2019-01-23 2019-01-24 2019-01-25
+#> 5: 2019 2019-05 2019-01-28 2019-01-29 2019-01-30 2019-01-31 2019-02-01
+#> 6: 2019 2019-06 2019-02-04 2019-02-05 2019-02-06 2019-02-07 2019-02-08
+#> sat sun weekdays
+#> 1: 2019-01-05 2019-01-06 2018-12-31,2019-01-01,2019-01-02,2019-01-03,2019-01-04
+#> 2: 2019-01-12 2019-01-13 2019-01-07,2019-01-08,2019-01-09,2019-01-10,2019-01-11
+#> 3: 2019-01-19 2019-01-20 2019-01-14,2019-01-15,2019-01-16,2019-01-17,2019-01-18
+#> 4: 2019-01-26 2019-01-27 2019-01-21,2019-01-22,2019-01-23,2019-01-24,2019-01-25
+#> 5: 2019-02-02 2019-02-03 2019-01-28,2019-01-29,2019-01-30,2019-01-31,2019-02-01
+#> 6: 2019-02-09 2019-02-10 2019-02-04,2019-02-05,2019-02-06,2019-02-07,2019-02-08
+#> weekend
+#> 1: 2019-01-05,2019-01-06
+#> 2: 2019-01-12,2019-01-13
+#> 3: 2019-01-19,2019-01-20
+#> 4: 2019-01-26,2019-01-27
+#> 5: 2019-02-02,2019-02-03
+#> 6: 2019-02-09,2019-02-10
+#> days
+#> 1: 2018-12-31,2019-01-01,2019-01-02,2019-01-03,2019-01-04,2019-01-05,...
+#> 2: 2019-01-07,2019-01-08,2019-01-09,2019-01-10,2019-01-11,2019-01-12,...
+#> 3: 2019-01-14,2019-01-15,2019-01-16,2019-01-17,2019-01-18,2019-01-19,...
+#> 4: 2019-01-21,2019-01-22,2019-01-23,2019-01-24,2019-01-25,2019-01-26,...
+#> 5: 2019-01-28,2019-01-29,2019-01-30,2019-01-31,2019-02-01,2019-02-02,...
+#> 6: 2019-02-04,2019-02-05,2019-02-06,2019-02-07,2019-02-08,2019-02-09,...
Season week (i.e. the week number within a season) conversion is used for certain outcomes of interest, such as influenza. It is frequently used for plotting purposes.
+Isoweek can be integers between 1 and 53. Season week can be integers between 1 and 52. When isoweek is 53, season week is 23.5.
+
+library(cstime)
+#> cstime 2023.12.6
+#> https://www.csids.no/cstime/
+library(magrittr)
+library(data.table)
+seasonweek_to_isoweek_c(10)
+#> [1] "10"
+seasonweek_to_isoweek_n(10)
+#> [1] 10
+isoweek_to_seasonweek_n(1)
+#> [1] 24
+seasonweek_to_isoweek_n(1:52)
+#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
+#> [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
+#> [51] 51 52
+isoweek_to_seasonweek_n(1:53)
+#> [1] 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0
+#> [16] 39.0 40.0 41.0 42.0 43.0 44.0 45.0 46.0 47.0 48.0 49.0 50.0 51.0 52.0 1.0
+#> [31] 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0
+#> [46] 17.0 18.0 19.0 20.0 21.0 22.0 23.0 23.5