View source: R/add_rolling_average.R
add_rolling_average | R Documentation |
add_rolling_average()
adds a rolling average to an <incidence2>
object.
If multiple groupings or count variables are present then the average will be
calculated for each.
add_rolling_average(
x,
n = 3L,
complete_dates = TRUE,
align = c("right", "center"),
colname = "rolling_average",
...
)
x |
|
n |
How many date groupings to consider in each window?
|
complete_dates |
Should Defaults to TRUE. |
align |
Character, specifying the "alignment" of the rolling window, defaulting to |
colname |
The name of the column to contain the rolling average. |
... |
Other arguments passed to |
The input object with an additional column for the rolling average.
if (requireNamespace("outbreaks", quietly = TRUE)) {
data(ebola_sim_clean, package = "outbreaks")
dat <- ebola_sim_clean$linelist
dat <- subset(dat, date_of_onset <= as.Date("2014-10-05"))
inci <- incidence2::incidence(
dat,
date_index = "date_of_onset",
groups = "gender",
interval = "isoweek"
)
add_rolling_average(inci, n = 3L)
inci2 <- incidence2::regroup(inci)
add_rolling_average(inci2, n = 7L)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.