data(iris)
# finding kNN directly in data (using a kd-tree)
nn <- kNN(iris[,-5], k=10)
nn
# explore neighborhood of point 10
i <- 10
nn$id[i,]
plot(iris[,-5], col = ifelse(1:nrow(iris) %in% nn$id[i,], "red", "black"))
Run the code above in your browser using DataLab