View source: R/time_is_regular.R
time_is_regular | R Documentation |
This function is a fast way to check if a time vector
is a regular sequence, possibly for many groups.
Regular in this context means that the lagged time differences are a
whole multiple of the specified time unit.
This means x
can be a regular sequence with or without gaps in time.
time_is_regular(
x,
timespan = granularity(x),
g = NULL,
use.g.names = TRUE,
na.rm = TRUE,
allow_gaps = FALSE,
allow_dups = FALSE
)
x |
Time vector. |
timespan |
timespan. |
g |
Grouping object passed directly to |
use.g.names |
Should the result include group names?
Default is |
na.rm |
Should |
allow_gaps |
Should gaps be allowed? Default is |
allow_dups |
Should duplicates be allowed? Default is |
A logical vector the same length as the number of supplied groups.
library(timeplyr)
library(lubridate)
library(dplyr)
x <- 1:5
y <- c(1, 1, 2, 3, 5)
# No duplicates or gaps allowed by default
time_is_regular(x)
time_is_regular(y)
increment <- 1
# duplicates and gaps allowed
time_is_regular(x, increment, allow_dups = TRUE, allow_gaps = TRUE)
time_is_regular(y, increment, allow_dups = TRUE, allow_gaps = TRUE)
# No gaps allowed
time_is_regular(x, increment, allow_dups = TRUE, allow_gaps = FALSE)
time_is_regular(y, increment, allow_dups = TRUE, allow_gaps = FALSE)
# Grouped
eu_stock <- ts_as_tbl(EuStockMarkets)
eu_stock <- eu_stock %>%
mutate(date = as_date(
date_decimal(time)
))
time_is_regular(eu_stock$date, g = eu_stock$group, timespan = 1,
allow_gaps = TRUE)
# This makes sense as no trading occurs on weekends and holidays
time_is_regular(eu_stock$date, g = eu_stock$group,
timespan = 1,
allow_gaps = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.