diff --git a/R/slide.R b/R/slide.R index 09596165..520e0621 100644 --- a/R/slide.R +++ b/R/slide.R @@ -477,28 +477,36 @@ epi_slide <- function(x, f, ..., before, after, ref_time_values, #' # slide a 7-day trailing average formula on cases #' jhu_csse_daily_subset %>% #' group_by(geo_value) %>% -#' epi_slide_mean(cases, new_col_name = cases_7dav, names_sep = NULL, before = 6) %>% +#' epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, before = 6) %>% #' # rmv a nonessential var. to ensure new col is printed #' dplyr::select(-death_rate_7d_av) #' +#' # slide a 7-day trailing average formula on cases. Adjust `frollmean` settings for speed +#' # and accuracy, and to allow partially-missing windows. +#' jhu_csse_daily_subset %>% +#' group_by(geo_value) %>% +#' epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, before = 6, +#' na.rm = TRUE, algo = "exact", hasNA = TRUE) %>% +#' dplyr::select(-death_rate_7d_av) +#' #' # slide a 7-day leading average #' jhu_csse_daily_subset %>% #' group_by(geo_value) %>% -#' epi_slide_mean(cases, new_col_name = cases_7dav, names_sep = NULL, after = 6) %>% +#' epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, after = 6) %>% #' # rmv a nonessential var. to ensure new col is printed #' dplyr::select(-death_rate_7d_av) #' #' # slide a 7-day centre-aligned average #' jhu_csse_daily_subset %>% #' group_by(geo_value) %>% -#' epi_slide_mean(cases, new_col_name = cases_7dav, names_sep = NULL, before = 3, after = 3) %>% +#' epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, before = 3, after = 3) %>% #' # rmv a nonessential var. to ensure new col is printed #' dplyr::select(-death_rate_7d_av) #' #' # slide a 14-day centre-aligned average #' jhu_csse_daily_subset %>% #' group_by(geo_value) %>% -#' epi_slide_mean(cases, new_col_name = cases_7dav, names_sep = NULL, before = 6, after = 7) %>% +#' epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, before = 6, after = 7) %>% #' # rmv a nonessential var. to ensure new col is printed #' dplyr::select(-death_rate_7d_av) epi_slide_mean = function(x, col_name, ..., before, after, ref_time_values, diff --git a/man/epi_slide_mean.Rd b/man/epi_slide_mean.Rd index 686204f5..f51be796 100644 --- a/man/epi_slide_mean.Rd +++ b/man/epi_slide_mean.Rd @@ -125,28 +125,36 @@ misspelled.) # slide a 7-day trailing average formula on cases jhu_csse_daily_subset \%>\% group_by(geo_value) \%>\% - epi_slide_mean(cases, new_col_name = cases_7dav, names_sep = NULL, before = 6) \%>\% + epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, before = 6) \%>\% # rmv a nonessential var. to ensure new col is printed dplyr::select(-death_rate_7d_av) +# slide a 7-day trailing average formula on cases. Adjust `frollmean` settings for speed +# and accuracy, and to allow partially-missing windows. +jhu_csse_daily_subset \%>\% + group_by(geo_value) \%>\% + epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, before = 6, + na.rm = TRUE, algo = "exact", hasNA = TRUE) \%>\% + dplyr::select(-death_rate_7d_av) + # slide a 7-day leading average jhu_csse_daily_subset \%>\% group_by(geo_value) \%>\% - epi_slide_mean(cases, new_col_name = cases_7dav, names_sep = NULL, after = 6) \%>\% + epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, after = 6) \%>\% # rmv a nonessential var. to ensure new col is printed dplyr::select(-death_rate_7d_av) # slide a 7-day centre-aligned average jhu_csse_daily_subset \%>\% group_by(geo_value) \%>\% - epi_slide_mean(cases, new_col_name = cases_7dav, names_sep = NULL, before = 3, after = 3) \%>\% + epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, before = 3, after = 3) \%>\% # rmv a nonessential var. to ensure new col is printed dplyr::select(-death_rate_7d_av) # slide a 14-day centre-aligned average jhu_csse_daily_subset \%>\% group_by(geo_value) \%>\% - epi_slide_mean(cases, new_col_name = cases_7dav, names_sep = NULL, before = 6, after = 7) \%>\% + epi_slide_mean("cases", new_col_name = "cases_7dav", names_sep = NULL, before = 6, after = 7) \%>\% # rmv a nonessential var. to ensure new col is printed dplyr::select(-death_rate_7d_av) }