Leave - one - out - Cross Validation KNN R
To learn how its done, simplest way is to give a try on sklearn and then try to implement the same by yourself-

https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.LeaveOneOut.html

and a very basic level explanation  here-
https://medium.com/@svanillasun/how-to-deal-with-cross-validation-based-on-knn-algorithm-compute-auc-based-on-naive-bayes-ff4b8284cff4