match_t: Matching Time Indices

View source: R/setops_match.R

match_tR Documentation

Matching Time Indices

Description

match_t and %in_t% allow for matching time indices to time intervals and to other sets of time indices including cases when table argument is of different type than x (of lower resolution).

Usage

match_t(x, table, nomatch = NA_integer_)

x %in_t% table

Arguments

x

an object of tind class.

table

an object of tinterval or tind class.

nomatch

an integer value to be returned when no match is found.

Details

%in_t% always returns TRUE/FALSE. NAs in x argument are never matched (FALSE is returned).

Value

match_t and %in_t% return integer and logical vectors, respectively. The length of the result equals length of x.

Note

Since match and %in% are not implemented in base as S3 generics, new functions had to be implemented.

Examples

# match dates to months
(x <- as.date("2025-03-02") + 15 * (0:5))
(table <- as.month("2025-03") + -1:1)
match_t(x, table)
# match dates to time intervals representing months
(table <- (as.date("2025-03-01") %--% as.date("2025-03-31")) %+m% (-1:1))
match_t(x, table)
# are dates in March 2025?
x %in_t% "2025-03"
# NAs are _never_ matched
(x <- as.date("2025-03-02") + c(NA, 15 * (0:5)))
(table <- as.month("2025-03") + c(NA, -1:1))
match_t(x, table)
x %in_t% table


tind documentation built on Dec. 28, 2025, 1:06 a.m.