Here's a possible approach using windowing, distance calculation, and k-NN algorithm. It assumes that the two time series are stored as vectors, ts1
and ts2
, of equal length, and that the length of each time series is larger than 10.
main.r875 chars27 lines
This approach uses the embed()
function to split the time series into sliding windows of size w_size
. The dist()
function from the proxy
package is used to compute the pairwise Euclidean distances between all windows of the two time series. Then, the get.knnx()
function from the FNN
package is used to find the k-NN for each window in ts1
. By default, get.knnx()
uses Euclidean distance to calculate the distances between windows. The resulting knn_result$nn.index
matrix has the indices of the k-NN for each window in ts1
.
gistlibby LogSnag