calculate_flu_start | R Documentation |
Assuming flu season starting on Sunday of week 35 each year, providing the year will return the full date this begins.
calculate_flu_start(
year = format(Sys.Date(), "%Y"),
week = NA,
flu_wk_start = 35L,
week_start = 7
)
year |
Character vector of years to determine flu week start dates (default is current year). |
week |
Optional parameter for higher resolution of flu week start based on |
flu_wk_start |
Week of the year that flu season begins (default set to 35). |
week_start |
Integer value for start of week (default: 7, Sunday). |
For a higher resolution, you can provide a week number to the week
parameter. For example, on week 1 of Jan 2023, it may be desired to
have the 2022 flu year as reference instead of 2023. This avoids some manipulation of inputs using other functions like convert_date2fluseason
.
However, unlike the year
parameter, this is not currently vectorized and requires mapply
to assist in looping, see examples.
Vector of dates.
## Not run:
# Find start dates for each week...
calculate_flu_start(2022); calculate_flu_start('2022');
calculate_flu_start('2022') + seq(0, 7*10, by =7)
calculate_flu_start(c(2020, 2021, 2022))
lapply(calculate_flu_start(c(2020, 2021, 2022)), function(x) x + seq(0, 7*10, by =7))
# Using weekly resolution
calculate_flu_start(2022, 34)
mapply(calculate_flu_start, c(2022, 2022), week = c(34,35), SIMPLIFY = FALSE) # As list
do.call('c', mapply(calculate_flu_start, c(2022, 2022), week = c(34,35), SIMPLIFY = FALSE)) # As vector
Reduce('c', mapply(calculate_flu_start, c(2022, 2022), week = c(34,35), SIMPLIFY = FALSE)) # Same as above in effect
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.