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

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)
#> # incidence:  8 x 4
#> # count vars: counts
#> # groups:     groups
#>   date_index groups count_variable count
#>   <date>     <chr>  <fct>          <int>
#> 1 2023-12-06 grp1   counts             1
#> 2 2023-12-06 grp2   counts             0
#> 3 2023-12-07 grp1   counts             0
#> 4 2023-12-07 grp2   counts             0
#> 5 2023-12-08 grp1   counts             0
#> 6 2023-12-08 grp2   counts             2
#> 7 2023-12-09 grp1   counts             3
#> 8 2023-12-09 grp2   counts             0