keep: Keep first, last and peak occurences

keepR Documentation

Keep first, last and peak occurences

Description

keep_first() and keep_last() keep the first and last n rows to occur for each grouping when in ascending date order. keep_peaks() keeps the rows with the maximum count value for each group.

Usage

keep_first(x, n, complete_dates = TRUE, ...)

keep_last(x, n, complete_dates = TRUE, ...)

keep_peaks(x, complete_dates = TRUE, first_only = FALSE, ...)

Arguments

x

⁠<incidence2>⁠ object.

n

⁠[integer]⁠

Number of entries to keep.

double vectors will be converted via as.integer(n).

complete_dates

⁠[bool]⁠

Should complete_dates() be called on the data prior to keeping the first entries.

Defaults to TRUE.

...

Other arguments passed to complete_dates().

first_only

⁠[bool]⁠

Should only the first peak (by date) be kept.

Defaults to TRUE.

Value

Incidence object with the chosen entries.

Examples


if (requireNamespace("outbreaks", quietly = TRUE)) {

    data(ebola_sim_clean, package = "outbreaks")
    dat <- ebola_sim_clean$linelist
    inci <- incidence(dat, "date_of_onset")
    keep_first(inci, 3)
    keep_last(inci, 3)

}


incidence2 documentation built on July 9, 2023, 5:35 p.m.