I recently came across a very similar question. I wanted to give only one column as a predictor. In such cases, when choosing a column, you should remember the drop argument and set it to FALSE. The knn() function accepts only matrices or data frames as arguments to the train and test. Not vectors.
knn(train = trainSet[, 2, drop = FALSE], test = testSet[, 2, drop = FALSE], cl = trainSet$Direction, k = 5)
crocodile
source share