[R] R Sig-Geo group - loop for creating spatial matrix

Giorgio Garziano giorgio.garziano at ericsson.com
Mon Feb 1 20:39:44 CET 2016


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]]



More information about the R-help mailing list