library(purrr)
cases <- 250
halving_thing <- function(cases, n_times){
purrr::accumulate(.x = rep(cases, n_times), .f = ~.x * 0.5)
}
halving_thing(532, 3)
#> [1] 532 266 133
halving_thing(227, 3)
#> [1] 227.00 113.50 56.75
date_today <- lubridate::today()
date_today + lubridate::period(num = 1, units = "week")
#> [1] "2020-10-13"
purrr::accumulate(.x = rep(date_today, 3),
.f =
~.x + lubridate::period(num = 1,
units = "week")) %>%
purrr::map(lubridate::as_date) %>%
purrr::map(c)
#> [[1]]
#> [1] "2020-10-06"
#>
#> [[2]]
#> [1] "2020-10-13"
#>
#> [[3]]
#> [1] "2020-10-20"
Created on 2020-10-06 by the reprex package (v0.3.0)