complete_dates: Complete dates for all group combinations

View source: R/complete_dates.R

complete_datesR Documentation

Complete dates for all group combinations

Description

This function ensures that an incidence object has the same range of dates for each grouping. By default missing counts will be filled with 0L.

Usage

complete_dates(x, expand = TRUE, fill = 0L, by = 1L, allow_POSIXct = FALSE)

Arguments

x

⁠<incidence2>⁠ object.

expand

logical.

Should a range of dates from the minimum to maximum value of the date index also be created.

If expand is TRUE (default) then complete_dates will attempt to use function(x) seq(min(x), max(x), by = 1) to generate a complete sequence of dates.

fill

numeric.

The value to replace missing counts by.

Defaults to 0L.

by

Defunct.

Ignored.

allow_POSIXct

logical.

Should this function work with POSIXct dates?

Defaults to FALSE.

Value

An incidence2 object.

Examples


x <- data.frame(
    dates = Sys.Date() + c(1,3,4),
    groups = c("grp1","grp2", "grp1"),
    counts = 1:3
)

i <- incidence(x, date_index = "dates", groups = "groups", counts = "counts")
complete_dates(i)



incidence2 documentation built on Oct. 7, 2024, 1:07 a.m.