I work with the knn algorithm in R.
The alogrithm selects the k "closest" points in feature space and calculates predictions/probabilities based on these k closest points.
My problem/question is: Can I specify a maximum distance? For some points the "k nearest neighbors" may be so far away that it would not make sense to use them. So I need an extended version of the algorithm that gives me an "NA", if all the closest points are "too far". I also like to be able to specify this threshold as a hyperparameter and to tune this later on.
Does such a variant exist? And is implemented in R already?