# Using kknn regression on a time series

I'm trying to perform a knn regression on a sales time series using the kknn package. I can't see how you can restrict the neighbours to past sales only though.

e.g.

Product, Price, Sale Date
A,       £100,  2012-01-04
A,       £100,  2012-01-05
A,       £200,  2012-01-06


If I want to predict for the second row, it should only consider the first row as a neighbour -- not the third.

Is there a way to do this or am I going to have to write something custom?

If it's going to have to be custom, what's the most efficient way of doing this in R? My dataset is 200,000 rows so I imagine it could be slow going using a loop.