epi_slide_opt | R Documentation |
epi_slide_opt
allows sliding an n-timestep data.table::froll
or slider::summary-slide function over variables in an epi_df
object.
These functions tend to be much faster than epi_slide()
. See
vignette("epi_df")
for more examples.
epi_slide_mean
is a wrapper around epi_slide_opt
with .f = datatable::frollmean
.
epi_slide_sum
is a wrapper around epi_slide_opt
with .f = datatable::frollsum
.
epi_slide_opt(
.x,
.col_names,
.f,
...,
.window_size = NULL,
.align = c("right", "center", "left"),
.ref_time_values = NULL,
.all_rows = FALSE
)
epi_slide_mean(
.x,
.col_names,
...,
.window_size = NULL,
.align = c("right", "center", "left"),
.ref_time_values = NULL,
.all_rows = FALSE
)
epi_slide_sum(
.x,
.col_names,
...,
.window_size = NULL,
.align = c("right", "center", "left"),
.ref_time_values = NULL,
.all_rows = FALSE
)
.x |
An |
.col_names |
< The tidy-selection renaming interface is not supported, and cannot be used
to provide output column names; if you want to customize the output column
names, use |
.f |
Function; together with The optimized |
... |
Additional arguments to pass to the slide computation |
.window_size |
The size of the sliding window. The accepted values
depend on the type of the
|
.align |
The alignment of the sliding window.
|
.ref_time_values |
The time values at which to compute the slides
values. By default, this is all the unique time values in |
.all_rows |
If |
An epi_df
object with one or more new slide computation columns
added.
epi_slide
for the more general slide function
# Compute a 7-day trailing average on cases.
cases_deaths_subset %>%
group_by(geo_value) %>%
epi_slide_opt(cases, .f = data.table::frollmean, .window_size = 7) %>%
dplyr::select(geo_value, time_value, cases, cases_7dav = slide_value_cases)
# Same as above, but adjust `frollmean` settings for speed, accuracy, and
# to allow partially-missing windows.
cases_deaths_subset %>%
group_by(geo_value) %>%
epi_slide_opt(
cases,
.f = data.table::frollmean, .window_size = 7,
algo = "exact", hasNA = TRUE, na.rm = TRUE
) %>%
dplyr::select(geo_value, time_value, cases, cases_7dav = slide_value_cases)
# Compute a 7-day trailing average on cases.
cases_deaths_subset %>%
group_by(geo_value) %>%
epi_slide_mean(cases, .window_size = 7) %>%
dplyr::select(geo_value, time_value, cases, cases_7dav = slide_value_cases)
# Same as above, but adjust `frollmean` settings for speed, accuracy, and
# to allow partially-missing windows.
cases_deaths_subset %>%
group_by(geo_value) %>%
epi_slide_mean(
cases,
.window_size = 7,
na.rm = TRUE, algo = "exact", hasNA = TRUE
) %>%
dplyr::select(geo_value, time_value, cases, cases_7dav = slide_value_cases)
# Compute a 7-day trailing sum on cases.
cases_deaths_subset %>%
group_by(geo_value) %>%
epi_slide_sum(cases, .window_size = 7) %>%
dplyr::select(geo_value, time_value, cases, cases_7dsum = slide_value_cases)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.