build_incidence() coerces an object to an incidence of events.

build_incidence(
  x,
  date_index,
  groups = NULL,
  counts = NULL,
  na_as_group = TRUE,
  FUN = identity,
  args = list()
)

Arguments

x

A data frame representing a linelist (or potentially a pre-aggregated dataset).

date_index

The time index(es) of the given data. Multiple inputs only make sense when x is a linelist, and in this situation, to avoid ambiguity, the vector must be named. These names will be used for the resultant count columns.

groups

An optional vector giving the names of the groups of observations for which incidence should be grouped.

counts

The count variables of the given data. If NULL (default) the data is taken to be a linelist of individual observations.

na_as_group

A logical value indicating if missing group values (NA) should treated as a separate category (TRUE) or removed from consideration (FALSE). Defaults to TRUE.

FUN

Function applied to the dates_index vectors before grouping. The first argument of FUN must work with a dates_index vector. Defaults to the identity function.

args

List of additional arguments passed to FUN.

Value

An incidence_df`` object. This is a subclass of [tibble][tibble::tbl-df`] represents an aggregated count of observations. It will contain the following columns:

date_index: If the default interval of 1 day is used then this will be the dates of the given observations and given the name "date", otherwise, this will be values obtained from the specified date grouping with column name "date_index" (See Interval specification below).

  • count (or name of count variables): The aggregated observation counts.

  • groups (if specified): column(s) containing the categories of the given groups.