Learn R Programming

incidence2 (version 2.2.3)

complete_dates: 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)

Value

An <incidence2> object.

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.

Examples

Run this code
data.table::setDTthreads(2)
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)

Run the code above in your browser using DataLab