To split a time series data to windows of length 10, you can use the rollapply
function from the zoo
package in R. Here's an example of how to do it:
main.r226 chars8 lines
Now that you have the windows, you can loop through each window and find the closest 5 preceding neighbors using weighted euclidean distance. Here's an example of how to do it using the Dist
function from the proxy
package:
main.r757 chars20 lines
Note that this code assumes that the time series data is in a vector format. If it's in a different format (e.g. a data frame), you may need to adjust the code accordingly. Additionally, this code only considers the weighted euclidean distance between rows within each window, so if you need to calculate the distances between rows in different windows, you'll need to modify the code accordingly.
gistlibby LogSnag