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]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.