Skip to contents

This function regroups an incidence2 object across the specified groups. The resulting incidence2 object will contains counts aggregated over the specified groups.

Usage

regroup(x, groups = NULL)

Arguments

x

<incidence2> object.

groups

character.

The groups to sum over.

If NULL (default) then the function returns the corresponding object with no groupings.

See also

regroup_() for a version supporting

Examples

if (requireNamespace("outbreaks", quietly = TRUE)) {
    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")
}
#> # 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