Learn R Programming

timeplyr (version 1.1.0)

time_gaps: 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,
  timespan = granularity(x),
  g = NULL,
  use.g.names = TRUE,
  check_time_regular = FALSE
)

time_num_gaps( x, timespan = granularity(x), g = NULL, use.g.names = TRUE, na.rm = TRUE, check_time_regular = FALSE )

time_has_gaps( x, timespan = granularity(x), g = NULL, use.g.names = TRUE, na.rm = TRUE, check_time_regular = FALSE )

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.

Arguments

x

Time vector.
E.g. a Date, POSIXt, numeric or any time-based vector.

timespan

timespan.

g

Grouping object passed directly to collapse::GRP(). This can for example be a vector or data frame.

use.g.names

Should the result include group names? Default is TRUE.

check_time_regular

Should the time vector be checked to see if it is regular (with or without gaps)? Default is FALSE.

na.rm

Should NA values be removed? Default is TRUE.

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.

Examples

Run this code

library(timeplyr)
library(fastplyr)
library(lubridate)
library(nycflights13)
missing_dates(flights$time_hour)
time_has_gaps(flights$time_hour)
time_num_gaps(flights$time_hour)
length(time_gaps(flights$time_hour))
time_num_gaps(flights$time_hour, g = flights$origin)

# Number of missing hours by origin and dest
flights %>%
  f_group_by(origin, dest) %>%
  f_summarise(n_missing = time_num_gaps(time_hour, "hours"))

Run the code above in your browser using DataLab