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 viaas.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)
}
#> # incidence: 3 x 3
#> # count vars: date_of_onset
#> date_index count_variable count
#> <date> <chr> <int>
#> 1 2015-04-28 date_of_onset 8
#> 2 2015-04-29 date_of_onset 2
#> 3 2015-04-30 date_of_onset 2