time_seq_id | R Documentation |
A unique identifier is created every time a specified amount of time has passed, or in the case of regular sequences, when there is a gap in time.
time_seq_id(
x,
timespan = granularity(x),
threshold = 1,
g = NULL,
na_skip = TRUE,
rolling = TRUE,
switch_on_boundary = FALSE
)
x |
Time vector. |
timespan |
timespan. |
threshold |
Threshold such that when the time elapsed
exceeds this, the sequence ID is incremented by 1.
For example, if |
g |
Object used for grouping x.
This can for example be a vector or data frame.
|
na_skip |
Should |
rolling |
When this is |
switch_on_boundary |
When an exact amount of time
(specified in |
time_seq_id()
Assumes x
is regular and in
ascending or descending order.
To check this condition formally, use time_is_regular()
.
An integer vector of length(x)
.
library(dplyr)
library(timeplyr)
library(lubridate)
# Weekly sequence, with 2 gaps in between
x <- time_seq(today(), length.out = 10, time = "week")
x <- x[-c(3, 7)]
# A new ID when more than a week has passed since the last time point
time_seq_id(x)
# A new ID when >= 2 weeks has passed since the last time point
time_seq_id(x, threshold = 2, switch_on_boundary = TRUE)
# A new ID when at least 4 cumulative weeks have passed
time_seq_id(x, timespan = "4 weeks",
switch_on_boundary = TRUE, rolling = FALSE)
# A new ID when more than 4 cumulative weeks have passed
time_seq_id(x, timespan = "4 weeks",
switch_on_boundary = FALSE, rolling = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.