Get all indices in neighbourhood

neighbour_idx(mat, idx, mask = NULL, diagonal = TRUE,
  include.idx = FALSE)

Arguments

mat

matrix or data.frame

idx

two-element vector

mask

logical matrix; optional

diagonal

include diagonal neighbours

include.idx

include current index

Examples

mat <- matrix(0, 3, 3) neighbour_idx(mat, c(1, 2))
#> [[1]] #> [1] 1 1 #> #> [[2]] #> [1] 1 3 #> #> [[3]] #> [1] 2 1 #> #> [[4]] #> [1] 2 2 #> #> [[5]] #> [1] 2 3 #>
neighbour_idx(mat, c(1, 2), diagonal = FALSE)
#> [[1]] #> [1] 1 1 #> #> [[2]] #> [1] 1 3 #> #> [[3]] #> [1] 2 2 #>
neighbour_idx(mat, c(1, 2), diagonal = FALSE, include.idx = TRUE)
#> [[1]] #> [1] 1 1 #> #> [[2]] #> [1] 1 2 #> #> [[3]] #> [1] 1 3 #> #> [[4]] #> [1] 2 2 #>
# With mask mat <- matrix(0, 3, 4) mask <- m(FALSE, FALSE, TRUE, TRUE | FALSE, FALSE, FALSE, FALSE | TRUE, TRUE, FALSE, TRUE) neighbour_idx(mat, c(1, 2), mask = mask)
#> [[1]] #> [1] 1 3 #>