View source: R/matrix_get_neighbors.R
matrix_get_neighbors | R Documentation |
Get the values of a k
*k
neighborhood, as vector and by row, given a matrix
, k
, and focal cell position (row and column).
matrix_get_neighbors(m, pos, k = 3)
m |
A |
pos |
The focal cell position, a |
k |
Neighborhood size around the focal cell. For example, |
A vector with cell values, ordered by rows, starting from the top left corner of the neighborhood and to the right. When neighborhood extends beyond matrix bounds, only the "existing" values are returned.
m = matrix(1:12, nrow = 3, ncol = 4)
m
matrix_get_neighbors(m, pos = c(2, 2), k = 3)
matrix_get_neighbors(m, pos = c(2, 2), k = 5)
matrix_get_neighbors(m, pos = c(2, 2), k = 7) # Same result
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.