add_rolling_average {i2extras} | R Documentation |
Add a rolling average
Description
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.
Usage
add_rolling_average(
x,
n = 3L,
complete_dates = TRUE,
align = c("right", "center"),
colname = "rolling_average",
...
)
Arguments
x |
|
n |
How many date groupings to consider in each window?
|
complete_dates |
Should Defaults to TRUE. |
align |
character, define if rolling window covers preceding rows
( |
colname |
The name of the column to contain the rolling average. |
... |
Other arguments passed to |
Value
The input object with an additional column for the rolling average.
Examples
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)
}