int_overlap | R Documentation |
Interval
objectsint_overlap()
computes the overlapping interval between two
Interval
objects.
See the Details section for more information.
int_overlap(int_1, int_2)
int_1 , int_2 |
|
The overlapping interval is the time span where both intervals intersect.
If the intervals do not overlap, the function returns an NA-NA
Interval
.
The illustration below demonstrates the concept:
+______________________+_________+ | | | | Interval 1 | | +______________________+_________+ |//////////////////////| |//// Overlap Area ////| +_______+//////////////////////+ | | | | | Interval 2 | +_______+______________________+
An Interval
vector with the overlapping
period between int_1
and int_2
.
Other Interval functions:
int_duration()
,
int_mean()
int_1 <- lubridate::interval(
start = lubridate::as_datetime("2020-01-01 00:00:00"),
end = lubridate::as_datetime("2021-01-01 00:00:00"),
)
int_2 <- lubridate::interval(
start = lubridate::as_datetime("2020-05-01 00:00:00"),
end = lubridate::as_datetime("2021-05-01 00:00:00"),
)
int_3 <- lubridate::interval(
start = lubridate::as_datetime("2021-01-01 00:00:00"),
end = lubridate::as_datetime("2025-01-01 00:00:00"),
)
int_overlap(int_1, int_2)
#> [1] 2020-05-01 UTC--2021-01-01 UTC # Expected
int_overlap(int_1, c(int_2, int_3))
#> [1] 2020-05-01 UTC--2021-01-01 UTC # Expected
#> [2] 2021-01-01 UTC--2021-01-01 UTC
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.