
Match the dates of a time-dependent variable with a predefined vector
Source:R/inter.R
matchtime.RdThe function takes a variable x (e.g. a vector or a list object), and reorders it to best match the dates provided in a vector y.
Usage
matchtime(x, y, ...)
# S4 method for numeric
matchtime(x, y, index = FALSE, ...)
# S4 method for character
matchtime(x, y, index = FALSE, ...)
# S4 method for list
matchtime(x, y, index = FALSE, ...)Arguments
- x
Object to be reordered to match
y.- y
(
numeric) The vector of dates (numeric values) to order to.- ...
Additional arguments passed to class-specific methods.
- index
(
logical) If this argument isTRUE, only the indices will be returned that refer to the new order, rather than the reorderedxvariable.
Examples
# original vector
orig <- 1:10
# target values
targ <- c(5.1,4.2, 3.4, 2.7, 2.3)
# how do the two series match the best?
matchtime(orig, targ)
#> [1] 5 4 3 3 2