While you can calculate the distance / difference matrix (no matter how you like it), you can easily classify kNN without the need for any special packaging.
# Generate dummy data y <- rep(1:2, each=50)
If anyone knows a better way to find the most common value in a vector than the dirty line above, I would be happy to know.
The drop=FALSE argument is needed to save the subset NN as a matrix in the case k=1 . If not, it will be converted to a vector and apply will apply error.
source share