Skip to contents

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)
#> # incidence:  8 x 4
#> # count vars: counts
#> # groups:     groups
#>   date_index groups count_variable count
#>   <date>     <chr>  <fct>          <int>
#> 1 2024-11-14 grp1   counts             1
#> 2 2024-11-14 grp2   counts             0
#> 3 2024-11-15 grp1   counts             0
#> 4 2024-11-15 grp2   counts             0
#> 5 2024-11-16 grp1   counts             0
#> 6 2024-11-16 grp2   counts             2
#> 7 2024-11-17 grp1   counts             3
#> 8 2024-11-17 grp2   counts             0