Neighbours list based on \(k\) nearest neighbours
In two steps:
knearneigh(): create aknnobject (‘k-nearest neighbour classification’)- it contains
nn: a matrix that defines the k nearest neighbors
- it contains
knn2nb(): convert theknnobject to a neighbours list
## [1] "knn"
## [1] "matrix" "array"
## [,1] [,2] [,3]
## [1,] 3 2 4
## [2,] 4 1 8
## [3,] 5 4 1
## [4,] 8 2 7
## [5,] 11 8 3
## [6,] 9 5 10