Giorgio Garziano
2016-Feb-01 19:39 UTC
[R] R Sig-Geo group - loop for creating spatial matrix
You may handle that as a list of "nb" objects. library(spdep) example(columbus) coord <- coordinates(columbus) z <- c(1,2,3,4,5,6,7,8,9) neighbors.knn <- list() for (val in z) { neighbors.knn <- c(neighbors.knn, list(knn2nb(knearneigh(coord, val, longlat=F), sym=F))) } class(neighbours.knn) class(neighbors.knn[[1]]) plot(neighbors.knn[[1]], coord) class(neighbors.knn[[2]]) plot(neighbors.knn[[2]], coord) and so on. Best, -- GG [[alternative HTML version deleted]]