gap_handler | R Documentation |
Datasets from light loggers often have implicit gaps. These gaps are implicit in the sense that consecutive timestamps (Datetimes
) might not follow a regular epoch/interval. This function fills these implicit gaps by creating a gapless sequence of Datetimes
and joining it to the dataset. The gapless sequence is determined by the minimum and maximum Datetime
in the dataset (per group) and an epoch. The epoch can either be guessed from the dataset or specified by the user. A sequence of gapless Datetimes
can be created with the gapless_Datetimes()
function, whereas the dominant epoch in the data can be checked with the dominant_epoch()
function. The behaviour
argument specifies how the data is combined. By default, the data is joined with a full join, which means that all rows from the gapless sequence are kept, even if there is no matching row in the dataset.
gap_handler(
dataset,
Datetime.colname = Datetime,
epoch = "dominant.epoch",
behavior = c("full_sequence", "regulars", "irregulars", "gaps"),
full.days = FALSE
)
dataset |
A light logger dataset. Needs to be a dataframe. |
Datetime.colname |
The column that contains the datetime. Needs to be a
|
epoch |
The epoch to use for the gapless sequence. Can be either a
|
behavior |
The behavior of the join of the |
full.days |
If |
A modified tibble
similar to dataset
but with handling of implicit gaps, depending on the behavior
argument:
"full_sequence"
adds timestamps to the dataset
that are missing based on a full sequence of Datetimes
(i.e., the gapless sequence). The dataset
is this equal (no gaps) or greater in the number of rows than the input. One column is added. is.implicit
indicates whether the row was added (TRUE
) or not (FALSE
). This helps differentiating measurement values from values that might be imputed later on.
"regulars"
keeps only rows from the gapless sequence that have a matching row in the dataset. This can be interpreted as a row-reduced dataset
with only regular timestamps according to the epoch
. In case of no gaps this tibble has the same number of rows as the input.
"irregulars"
keeps only rows from the dataset
that do not follow the regular sequence of Datetimes
according to the epoch
. In case of no gaps this tibble has 0 rows.
"gaps"
returns a tibble
of all implicit gaps in the dataset. In case of no gaps this tibble has 0 rows.
Other regularize:
dominant_epoch()
,
gap_finder()
,
gapless_Datetimes()
dataset <-
tibble::tibble(Id = c("A", "A", "A", "B", "B", "B"),
Datetime = lubridate::as_datetime(1) +
lubridate::days(c(0:2, 4, 6, 8)) +
lubridate::hours(c(0,12,rep(0,4)))) %>%
dplyr::group_by(Id)
dataset
#assuming the epoch is 1 day, we can add implicit data to our dataset
dataset %>% gap_handler(epoch = "1 day")
#we can also check whether there are irregular Datetimes in our dataset
dataset %>% gap_handler(epoch = "1 day", behavior = "irregulars")
#to get to the gaps, we can use the "gaps" behavior
dataset %>% gap_handler(epoch = "1 day", behavior = "gaps")
#finally, we can also get just the regular Datetimes
dataset %>% gap_handler(epoch = "1 day", behavior = "regulars")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.