# calculate full adjacency matrix
get_adjacencies(landscape, 4)
# count diagonal neighbour adjacencies
diagonal_matrix <- matrix(c(1, NA, 1,
NA, 0, NA,
1, NA, 1), 3, 3, byrow = TRUE)
get_adjacencies(landscape, diagonal_matrix)
# equivalent with the raster package:
adjacencies <- raster::adjacent(landscape, 1:raster::ncell(landscape), 4, pairs=TRUE)
table(landscape[adjacencies[,1]], landscape[adjacencies[,2]])
Run the code above in your browser using DataLab