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. first_peak() is a convenience wrapper around keep_peaks() with the first_only argument set to TRUE.

Usage

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

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

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

first_peak(x, complete_dates = TRUE, ...)

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

incidence2 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 Oct. 7, 2024, 1:07 a.m.