Learn R Programming

CAWaR (version 0.0.2)

matchIndices: matchIndices

Description

Matches two vectors with different lengths based on their maximum value.

Usage

matchIndices(x, y, z)

Arguments

x

Target numeric vector.

y

Reference numeric vector.

z

A numeric element.

Value

A list with selected indices for x and y.

Details

Uses Dynamic Time Wrapping (DTW) to match x and y. z determines the buffer size - expressed in number of data points - used to search for matching records.

Examples

Run this code
# NOT RUN {
{

x <- c(2200, 4500, 4600, 6400, 1600) # target
y <- c(1100, 1150, 1200, 6400, 1600) # reference

i <- matchIndices(x, y, 1) # find best match

# plot x (blue), and selected y (red)
plot(1:5, replicate(5,0), ylim=c(0,10000), type="l") 
lines(i$x, x[i$x], type="l", col="blue")
lines(i$y, y[i$y], type="l", col="red")

}
# }

Run the code above in your browser using DataLab