int_overlap: Compute the overlapping interval between two 'Interval'...

View source: R/int_overlap.R

int_overlapR Documentation

Compute the overlapping interval between two Interval objects

Description

[Maturing]

int_overlap() computes the overlapping interval between two Interval objects.

See the Details section for more information.

Usage

int_overlap(int_1, int_2)

Arguments

int_1, int_2

Interval vectors. If they have a length of '1“, they will be recycled to the length of the longest.

Details

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          |
  +_______+______________________+

Value

An Interval vector with the overlapping period between int_1 and int_2.

See Also

Other Interval functions: int_duration(), int_mean()

Examples

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

gipso/lubritime documentation built on April 17, 2025, 12:03 p.m.