dplyr-verbs | R Documentation |
dplyr and tidyr methods that implicitly account for the inherent grouping structure of incidence2 objects.
## S3 method for class 'incidence2'
mutate(
.data,
...,
.by,
.keep = c("all", "used", "unused", "none"),
.before = NULL,
.after = NULL
)
## S3 method for class 'incidence2'
nest(.data, ..., .by, .key, .names_sep)
## S3 method for class 'incidence2'
summarise(.data, ..., .by, .groups)
.data |
An incidence2 object. |
... |
Only used by |
.by |
Not used as grouping structure implicit. |
.keep |
Control which columns from
|
.before , .after |
< |
.key |
The name of the resulting nested column. Only applicable when
If |
.names_sep |
Not used. |
.groups |
Not used. |
For mutate()
a modified incidence2 object if the
necessary invariants are preserved, otherwise a tibble.
For nest()
a nested tibble with rows corresponding to
the count variable and (optionally) group columns of the input object.
For summarise a tibble with rows corresponding to the underlying groupings. The columns are a combination of the grouping keys and the summary expressions provided.
dplyr::mutate, tidyr::nest and dplyr::summarise for the underlying generics.
if (requireNamespace("outbreaks", quietly = TRUE) && requireNamespace("ggplot2", quietly = TRUE)) {
data(ebola_sim_clean, package = "outbreaks")
x <- subset(ebola_sim_clean$linelist, !is.na(hospital))
dat <- incidence_(x, date_of_onset, hospital, interval = "isoweek")
mutate(dat, ave = data.table::frollmean(count, n = 3L, align = "right")) |>
plot(border_colour = "white", angle = 45) +
ggplot2::geom_line(ggplot2::aes(x = date_index, y = ave))
nest(dat)
summarise(dat, model = list(glm(count ~ date_index, family = "poisson")))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.