time_by | R Documentation |
time_by
groups a time variable by a specified time unit like
for example "days" or "weeks".
It can be used exactly like dplyr::group_by
.
time_by(data, time, width = NULL, .name = NULL, .add = TRUE)
time_tbl_time_col(x)
data |
A data frame. |
time |
Time variable (data-masking). |
width |
A timespan. |
.name |
An optional glue specification passed to |
.add |
Should the time groups be added to existing groups?
Default is |
x |
A |
A time_tbl_df
which for practical purposes can be treated the
same way as a dplyr grouped_df
.
library(dplyr)
library(timeplyr)
library(fastplyr)
library(nycflights13)
library(lubridate)
# Basic usage
hourly_flights <- flights %>%
time_by(time_hour) # Detects time granularity
hourly_flights
monthly_flights <- flights %>%
time_by(time_hour, "month")
weekly_flights <- flights %>%
time_by(time_hour, "week")
monthly_flights %>%
f_count()
weekly_flights %>%
f_summarise(n = n(), arr_delay = mean(arr_delay, na.rm = TRUE))
# To aggregate multiple variables, use time_aggregate
flights %>%
f_count(week = time_cut_width(time_hour, months(3)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.