library(timeplyr)
library(dplyr)
library(lubridate)
library(nycflights13)
x <- unique(flights$time_hour)
# Number of missing hours
time_num_gaps(x)
# Same as above
time_grid_size(x) - length(unique(x))
# Time sequence that spans the data
length(time_grid(x)) # Automatically detects hour granularity
time_grid(x, "month")
time_grid(x, from = floor_date(min(x), "month"), to = today(),
timespan = timespan("month"))
# Complete missing gaps in time using time_complete
y <- time_complete_missing(x, "hour")
identical(y[!y %in% x], time_gaps(x))
# Summarise time into higher intervals
quarters <- time_cut_width(y, "quarter")
interval_count(quarters)
Run the code above in your browser using DataLab