
adjacent(x, cells, directions=4, pairs=TRUE, target=NULL, sorted=FALSE,
include=FALSE, id=FALSE)
TRUE
, a matrix of pairs of adjacent cells is returned. If FALSE
, a vector of cells adjacent to cells
is returnedr <- raster(nrows=10, ncols=10)
adjacent(r, cells=c(1, 55), directions=8, pairs=TRUE)
a <- adjacent(r, cell = c(1,55,90), directions=4, sorted=TRUE)
a
r[c(1,55,90)] <- 1
r[a] <- 2
plot(r)
# same result as above
rook <- matrix(c(NA, 1, NA,
1, 0, 1,
NA, 1, NA), ncol=3, byrow=TRUE)
adjacent(r, cells = c(1,55,90), directions=rook, sorted=TRUE)
Run the code above in your browser using DataLab