count_gaps: Count implicit gaps

View source: R/gaps.R

count_gapsR Documentation

Count implicit gaps

Description

Count implicit gaps

Usage

count_gaps(
  .data,
  .full = FALSE,
  .name = c(".from", ".to", ".n"),
  .start = NULL,
  .end = NULL
)

Arguments

.data

A tsibble.

.full
  • FALSE inserts NA for each keyed unit within its own period.

  • TRUE fills NA over the entire time span of the data (a.k.a. fully balanced panel).

  • start() pad NA to the same starting point (i.e. min(<index>)) across units.

  • end() pad NA to the same ending point (i.e. max(<index>)) across units.

.name

Strings to name new columns.

.start, .end

Set custom starting/ending time that allows to expand the existing time spans.

Value

A tibble contains:

  • the "key" of the tbl_ts

  • ".from": the starting time point of the gap

  • ".to": the ending time point of the gap

  • ".n": the number of implicit missing observations during the time period

See Also

Other implicit gaps handling: fill_gaps(), has_gaps(), scan_gaps()

Examples

ped_gaps <- pedestrian %>%
  count_gaps(.full = TRUE)
ped_gaps
if (!requireNamespace("ggplot2", quietly = TRUE)) {
  stop("Please install the ggplot2 package to run these following examples.")
}
library(ggplot2)
ggplot(ped_gaps, aes(x = Sensor, colour = Sensor)) +
  geom_linerange(aes(ymin = .from, ymax = .to)) +
  geom_point(aes(y = .from)) +
  geom_point(aes(y = .to)) +
  coord_flip() +
  theme(legend.position = "bottom")

tsibble documentation built on Oct. 9, 2022, 9:05 a.m.