set.seed(10)
nr <- nc <- 10
r <- terra::rast(
ncols = nc, nrows = nr,
ext = c(0, nc, 0, nr),
vals = sample(c(NA, 1, 2), nr * nc, replace = TRUE, prob = c(0.8, 0.1, 0.1))
)
terra::plot(r)
adj1 <- get_adjacent(r)
terra::plot(adj1)
adj2 <- get_adjacent(r, cells = 1, include = FALSE)
terra::plot(adj2)
Run the code above in your browser using DataLab