Learn R Programming

phinterval (version 1.0.0)

as_phinterval: Convert an interval or datetime vector into a phinterval

Description

as_phinterval() converts a lubridate::interval(), Date, POSIXct, or POSIXlt vector into an equivalent <phinterval> vector.

Usage

as_phinterval(x, ...)

# S3 method for default as_phinterval(x, ...)

# S3 method for Interval as_phinterval(x, ...)

Value

A <phinterval> vector the same length as x.

Arguments

x

[Interval / Date / POSIXct / POSIXlt]

An object to convert.

...

Additional arguments passed to methods. Currently unused.

Details

Negative intervals (where start > end) are standardized to positive intervals via lubridate::int_standardize().

Datetime vectors (Date, POSIXct, POSIXlt) are converted into instantaneous intervals where the start and end are identical.

Spans with partially missing endpoints (e.g., interval(NA, end) or interval(start, NA)) are converted to a fully NA element.

See Also

phinterval()

Examples

Run this code
# Convert Interval vector
years <- interval(
  start = as.Date(c("2021-01-01", "2023-01-01")),
  end = as.Date(c("2022-01-01", "2024-01-01"))
)
as_phinterval(years)

# Negative intervals are standardized
negative <- interval(as.Date("2000-10-11"), as.Date("2000-10-01"))
as_phinterval(negative)

# Partially missing endpoints become fully NA
partial_na <- interval(NA, as.Date("1999-08-02"))
as_phinterval(partial_na)

# Datetime vectors become instantaneous intervals
as_phinterval(as.Date(c("2000-10-11", "2001-05-03")))

Run the code above in your browser using DataLab