count_neighbours: Count neighbours for each element in a binary matrix

View source: R/utils.R

count_neighboursR Documentation

Count neighbours for each element in a binary matrix

Description

Count neighbours for each element in a binary matrix

Usage

count_neighbours(x)

Arguments

x

The matrix to count the neighbours in.

Value

A matrix of the same size as x giving the number of elements with non-zero values in neighbouring cells of the matrix.

Examples


x <- matrix(
c(1L, 1L, 0L,
  1L, 1L, 0L,
  0L, 1L, 1L),
nrow = 3,
ncol = 3,
byrow = TRUE
)
beadplexr:::count_neighbours(x)

x <- matrix(
  c(TRUE, TRUE, FALSE,
    TRUE, TRUE, FALSE,
   FALSE, TRUE, TRUE),
  nrow = 3,
  ncol = 3,
 byrow = TRUE
)
beadplexr:::count_neighbours(x)

x <- matrix(
  c(1, 1, 0, 0,
    1, 0, 0, 0,
    0, 1, 1 ,1,
    0, 1, 1, 1),
  nrow = 4,
  ncol = 4,
  byrow = TRUE
)
beadplexr:::count_neighbours(x)

## Not run: 
  x <- matrix(
    c("1", "1", "0",
      "1", "1", "0",
      "0", "1", "1"),
    nrow = 3,
    ncol = 3,
    byrow = TRUE
  )
  #beadplexr:::count_neighbours(x)

## End(Not run)


beadplexr documentation built on July 9, 2023, 5:59 p.m.