time_gaps {timeplyr} | R Documentation |
Gaps in a regular time sequence
Description
time_gaps()
checks for implicit missing gaps in time for any
regular date or datetime sequence.
Usage
time_gaps(
x,
time_by = NULL,
g = NULL,
use.g.names = TRUE,
time_type = getOption("timeplyr.time_type", "auto"),
check_time_regular = FALSE
)
time_num_gaps(
x,
time_by = NULL,
g = NULL,
use.g.names = TRUE,
na.rm = TRUE,
time_type = getOption("timeplyr.time_type", "auto"),
check_time_regular = FALSE
)
time_has_gaps(
x,
time_by = NULL,
g = NULL,
use.g.names = TRUE,
na.rm = TRUE,
time_type = getOption("timeplyr.time_type", "auto"),
check_time_regular = FALSE
)
Arguments
x |
A date, datetime or numeric vector. |
time_by |
Time unit.
|
g |
Grouping object passed directly to |
use.g.names |
Should the result include group names?
Default is |
time_type |
Time type, either "auto", "duration" or "period".
With larger data, it is recommended to use |
check_time_regular |
Should the time vector be
checked to see if it is regular (with or without gaps)?
Default is |
na.rm |
Should |
Details
When check_time_regular
is TRUE, x
is passed to
time_is_regular
, which checks that the time elapsed between successive
values are in increasing order and are whole numbers.
For more strict checks, see ?time_is_regular
.
Value
time_gaps
returns a vector of time gaps.
time_num_gaps
returns the number of time gaps.
time_has_gaps
returns a logical(1) of whether there are gaps.
Examples
library(timeplyr)
library(dplyr)
library(lubridate)
library(nycflights13)
missing_dates(flights$time_hour)
time_has_gaps(flights$time_hour)
time_num_gaps(flights$time_hour)
time_gaps(flights$time_hour)
time_num_gaps(flights$time_hour, g = flights$origin)
# Number of missing hours by origin and dest
flights %>%
group_by(origin, dest) %>%
summarise(n_missing = time_num_gaps(time_hour, "hours"))