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

timematch

match two (time) sequences


Description

match two (time) sequences, where each can be intervals or instances.

Usage

timeMatch(x, y, returnList = FALSE, ...)

Arguments

x

ordered sequence, e.g. of time stamps

y

ordered sequence, e.g. of time stamps

returnList

boolean; should a list be returned with all matches (TRUE), or a vector with single matches (FALSE)?

...

end.x and end.y can be specified for xts and POSIXct methods

Details

When x and y are of class xts or POSIXct, end.x and end.y need to specify endpoint of intervals.

In case x and y are both not intervals, matching is done on equality of values, using match.

If x represents intervals, then the first interval is from x[1] to x[2], with x[1] included but x[2] not (left-closed, right-open). In case of zero-width intervals (e.g. x[1]==x[2]), nothing will match and a warning is raised. Package intervals is used to check overlap of intervals, using, interval_overlap.

Value

if returnList = FALSE: integer vector of length length(x) with indexes of y matching to each of the elements of x, or NA if there is no match. See section details for definition of match.

if returnList = TRUE: list of length length(x), with each list element an integer vector with all the indexes of y matching to that element of x.

Author(s)

Edzer Pebesma

References

https://www.jstatsoft.org/v51/i07/

See Also

Examples

t0 = as.POSIXct("1999-10-10")
x = t0 +c(0.5+c(2,2.1,4),5)*3600
y = t0 + 1:5 * 3600
x
y
#timeIsInterval(x) = FALSE
#timeIsInterval(y) = FALSE
timeMatch(x,y, returnList = FALSE)
timeMatch(x,y, returnList = TRUE)
#timeIsInterval(y) = TRUE
timeMatch(x,y, returnList = FALSE, end.y = delta(y))
timeMatch(x,y, returnList = TRUE, end.y = delta(y))
#timeIsInterval(x) = TRUE
timeMatch(x,y, returnList = FALSE, end.x = delta(x), end.y = delta(y))
timeMatch(x,y, returnList = TRUE, end.x = delta(x), end.y = delta(y))
#timeIsInterval(y) = FALSE
timeMatch(x,y, returnList = FALSE, end.x = delta(x))
timeMatch(x,y, returnList = TRUE, end.x = delta(x))

x = as.POSIXct("2000-01-01") + (0:9) * 3600
y = x + 1
y[1] = y[2]
x
y
TI = function(x, ti) { 
	timeIsInterval(x) = ti
	x 
}
#timeMatch(TI(y,FALSE),TI(y,FALSE))
#timeMatch(TI(y,TRUE), TI(y,TRUE))
#
#timeMatch(TI(x,FALSE),TI(y,FALSE))
#timeMatch(TI(x,FALSE),TI(y,TRUE))
#timeMatch(TI(x,TRUE), TI(y,FALSE))
#timeMatch(TI(x,TRUE), TI(y,TRUE))
#
#timeMatch(TI(x,FALSE),TI(y,FALSE), returnList = TRUE)
#timeMatch(TI(x,FALSE),TI(y,TRUE), returnList = TRUE)
#timeMatch(TI(x,TRUE), TI(y,FALSE), returnList = TRUE)
#timeMatch(TI(x,TRUE), TI(y,TRUE), returnList = TRUE)

spacetime

Classes and Methods for Spatio-Temporal Data

v1.2-4
GPL (>= 2)
Authors
Edzer Pebesma [aut, cre] (<https://orcid.org/0000-0001-8049-7069>), Benedikt Graeler [ctb], Tom Gottfried [ctb], Robert J. Hijmans [ctb]
Initial release

We don't support your browser anymore

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