Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

matchtime

Match the dates of a time-dependent variable with a predefined vector


Description

The function takes a variable x (e.g. a vector or a RasterArray object), and reorders it to best match the dates provided in a vector y.

Usage

matchtime(x, y, ...)

## S4 method for signature 'numeric'
matchtime(x, y, index = FALSE, ...)

## S4 method for signature 'character'
matchtime(x, y, index = FALSE, ...)

## S4 method for signature 'RasterArray'
matchtime(x, y, index = FALSE, time = 1, ...)

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 is TRUE, only the indices will be returned that refer to the new order, rather than the reordered x variable.

time

numeric. Single value referring to that dimension of x where the time-coding names are (time=1 is the default for RasterArrays in chronosphere).

Value

An object of the class as x or a numeric vector.

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)

chronosphere

Earth System History Variables

v0.4.1
CC BY 4.0
Authors
Adam T. Kocsis, Nussaibah B. Raja
Initial release
2021-04-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.