
Last chance! 50% off unlimited learning
Sale ends in
count_gaps()
counts gaps for a tsibble; gaps()
find where the gaps in x
with respect to y
.
count_gaps(.data, ...)# S3 method for tbl_ts
count_gaps(.data, ...)
# S3 method for grouped_ts
count_gaps(.data, .full = FALSE, ...)
gaps(x, y)
A tbl_ts
.
Other arguments passed on to individual methods.
FALSE
to find gaps for each group within its own period. TRUE
to find gaps over the entire time span of the data.
A vector of numbers, dates, or date-times. The length of y
must
be greater than the length of x
.
A tibble contains:
the "key" of the tbl_ts
"from": the starting time point of the gap
"end": the ending time point of the gap
"n": the implicit missing observations during the time period
# NOT RUN {
# Implicit missing time without group_by ----
# All the sensors have 2 common missing time points in the data
count_gaps(pedestrian)
# Time gaps for each sensor per month ----
pedestrian %>%
index_by(yrmth = yearmonth(Date)) %>%
group_by(Sensor) %>%
count_gaps()
# Time gaps for each sensor ----
ped_gaps <- pedestrian %>%
group_by(Sensor) %>%
count_gaps(.full = TRUE)
if (!requireNamespace("ggplot2", quietly = TRUE)) {
stop("Please install the ggplot2 package to run these following examples.")
}
library(ggplot2)
ggplot(ped_gaps, aes(colour = Sensor)) +
geom_linerange(aes(x = Sensor, ymin = from, ymax = to)) +
geom_point(aes(x = Sensor, y = from)) +
geom_point(aes(x = Sensor, y = to)) +
coord_flip() +
theme(legend.position = "bottom")
# Vectors ----
gaps(x = c(1:3, 5:6, 9:10), y = 1:10)
# }
Run the code above in your browser using DataLab