View source: R/aggregate_period.R
| collapse_to_period | R Documentation |
Snaps each row's ds to the start of its period (per date_agg) and
combines rows that land on the same period (and, if group_col is
supplied, the same group) – e.g. case data split by district/sex/age
with many rows per Year+Quarter.
collapse_to_period(
df,
date_agg = "day",
fun = c("sum", "mean", "median", "none"),
group_col = NULL
)
df |
A data frame with |
date_agg |
Aggregation frequency: one of |
fun |
How to combine rows sharing a period: |
group_col |
Optional character scalar; rows only collapse together if they share both a period and this column's value. |
A tibble with one row per period (and group, if group_col is
supplied), columns ds/y(/group_col).
df <- data.frame(ds = as.Date(c("2024-01-01", "2024-01-02")), y = c(3, 5))
collapse_to_period(df, date_agg = "month")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.