Description Usage Arguments Examples
group_by_period
takes a date column and a numeric column and aggregates
the numeric column over specified date period. This is a common pattern in
data analysis in business where we want to convert transactional data to
daily, weekly or monthly data.
1 2 | group_by_period(.data, .date_col, .summarise_col, unit, agg_fun = sum,
na.rm = FALSE)
|
.data |
A |
.date_col |
A date column that will be used for grouping the date.
This should be of type |
.summarise_col |
The column which will be aggregated |
unit |
A character string specifying a time unit or a multiple of
a unit to be rounded to. See |
agg_fun |
A function used to aggregate the numeric column |
na.rm |
|
1 2 3 4 5 6 7 8 9 10 11 12 | library(nycflights13)
library(tidyr)
library(dplyr)
data("flights")
flights_w_date <- flights %>%
unite(flight_date, year, month, day, sep = "-") %>%
mutate(flight_date = ymd(flight_date))
flights_w_date %>%
group_by_period(flight_date, distance, "month")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.