| match_t | R Documentation |
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).
match_t(x, table, nomatch = NA_integer_)
x %in_t% table
x |
an object of |
table |
an object of |
nomatch |
an integer value to be returned when no match is found. |
%in_t% always returns TRUE/FALSE. NAs
in x argument are never matched (FALSE is returned).
match_t and %in_t% return integer and logical vectors,
respectively. The length of the result equals length of x.
Since match and %in% are not implemented in base as
S3 generics, new functions had to be implemented.
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.