Find the increasing subsets of \(k\) nearest neighbors for all locations.
Source:R/zones.R
knn_zones.Rd
Returns the set of increasing nearest neighbor sets for all locations, as a list of integer vectors. That is, for each location the list returned contains one vector containing the location itself, another containing the location and its nearest neighbor, and so on, up to the vector containing the location and its \(k-1\) nearest neighbors.
Arguments
- k_nearest
An integer matrix of with \(k\) columns and as many rows as locations. The first element of each row is the integer encoding the location (and equal to the row number); the following elements are the \(k-1\) nearest neighbors in ascending order of distance.
Examples
nn <- matrix(c(1L, 2L, 4L, 3L, 5L,
2L, 1L, 3L, 4L, 5L,
3L, 2L, 4L, 1L, 5L,
4L, 1L, 2L, 3L, 5L,
5L, 3L, 4L, 2L, 1L),
ncol = 5, byrow = TRUE)
knn_zones(nn[, 1:3])
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 1 2
#>
#> [[3]]
#> [1] 1 2 4
#>
#> [[4]]
#> [1] 2
#>
#> [[5]]
#> [1] 1 2 3
#>
#> [[6]]
#> [1] 3
#>
#> [[7]]
#> [1] 2 3
#>
#> [[8]]
#> [1] 2 3 4
#>
#> [[9]]
#> [1] 4
#>
#> [[10]]
#> [1] 1 4
#>
#> [[11]]
#> [1] 5
#>
#> [[12]]
#> [1] 3 5
#>
#> [[13]]
#> [1] 3 4 5
#>