This function regroups an incidence() object across the specified groups. The resulting incidence() object will contains counts summed over the groups present in the input.

regroup(x, groups = NULL)

Arguments

x

An incidence() object.

groups

The groups to sum over. If NULL (default) then the function ignores all groups.

Examples

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)
#> An incidence object: 367 x 2
#> date range: [2014-04-07] to [2015-04-30]
#> cases: 5829
#> interval: 1 day
#> cumulative: FALSE
#> 
#>    date_index count
#>    <date>     <int>
#>  1 2014-04-07     1
#>  2 2014-04-15     1
#>  3 2014-04-21     2
#>  4 2014-04-25     1
#>  5 2014-04-26     1
#>  6 2014-04-27     1
#>  7 2014-05-01     2
#>  8 2014-05-03     1
#>  9 2014-05-04     1
#> 10 2014-05-05     1
#> # … with 357 more rows
#> > regroup(i, hospital)
#> An incidence object: 1,635 x 3
#> date range: [2014-04-07] to [2015-04-30]
#> cases: 5829
#> interval: 1 day
#> cumulative: FALSE
#> 
#>    date_index hospital                                     count
#>    <date>     <fct>                                        <int>
#>  1 2014-04-07 Military Hospital                                1
#>  2 2014-04-15 Connaught Hospital                               1
#>  3 2014-04-21 other                                            2
#>  4 2014-04-25 NA                                               1
#>  5 2014-04-26 other                                            1
#>  6 2014-04-27 NA                                               1
#>  7 2014-05-01 Princess Christian Maternity Hospital (PCMH)     1
#>  8 2014-05-01 Rokupa Hospital                                  1
#>  9 2014-05-03 Connaught Hospital                               1
#> 10 2014-05-04 NA                                               1
#> # … with 1,625 more rows