This function regroups an <incidence2>
object across the specified groups.
The resulting <incidence2>
object will contains counts summed over the
groups present in the input.
Arguments
- x
<incidence2>
object.- groups
[character]
The groups to sum over.
If
NULL
(default) then the function returns the corresponding object with no groupings.
Examples
data.table::setDTthreads(2)
if (requireNamespace("outbreaks", quietly = TRUE)) {
withAutoprint({
data(ebola_sim_clean, package = "outbreaks")
dat <- ebola_sim_clean$linelist
i <- incidence(
dat,
date_index = "date_of_onset",
groups = c("gender", "hospital")
)
regroup(i)
regroup(i, "hospital")
})
}
#> > data(ebola_sim_clean, package = "outbreaks")
#> > dat <- ebola_sim_clean$linelist
#> > i <- incidence(dat, date_index = "date_of_onset", groups = c("gender",
#> + "hospital"))
#> > regroup(i)
#> # incidence: 367 x 3
#> # count vars: date_of_onset
#> date_index count_variable count
#> * <date> <chr> <int>
#> 1 2014-04-07 date_of_onset 1
#> 2 2014-04-15 date_of_onset 1
#> 3 2014-04-21 date_of_onset 2
#> 4 2014-04-25 date_of_onset 1
#> 5 2014-04-26 date_of_onset 1
#> 6 2014-04-27 date_of_onset 1
#> 7 2014-05-01 date_of_onset 2
#> 8 2014-05-03 date_of_onset 1
#> 9 2014-05-04 date_of_onset 1
#> 10 2014-05-05 date_of_onset 1
#> # ℹ 357 more rows
#> > regroup(i, "hospital")
#> # incidence: 1,635 x 4
#> # count vars: date_of_onset
#> # groups: hospital
#> date_index hospital count_variable count
#> * <date> <fct> <chr> <int>
#> 1 2014-04-07 Military Hospital date_of_onset 1
#> 2 2014-04-15 Connaught Hospital date_of_onset 1
#> 3 2014-04-21 other date_of_onset 2
#> 4 2014-04-25 NA date_of_onset 1
#> 5 2014-04-26 other date_of_onset 1
#> 6 2014-04-27 NA date_of_onset 1
#> 7 2014-05-01 Princess Christian Maternity Hospital (PCMH) date_of_onset 1
#> 8 2014-05-01 Rokupa Hospital date_of_onset 1
#> 9 2014-05-03 Connaught Hospital date_of_onset 1
#> 10 2014-05-04 NA date_of_onset 1
#> # ℹ 1,625 more rows