While answering a question on R-help, I was monkeying with the code in
cell2nb in spdep (5.11) to see if it can be made faster.
Getting rid of the for loop and replacing with lapply and apply only
marginally improves the performance
n <- nrow*ncol
for (i in 1:n) {
res[[i]] <- sort(mrc2vi(xcell(vi2mrc(i, nrow, ncol),
nrow, ncol, torus), nrow, ncol))
rownames[i] <- paste(vi2mrc(i, nrow, ncol), collapse = ":")
}
However, I do not understand why the loop has to run through 1:n. If
the adjacency matrix is symmertic, should we not just make ceil[n/2]
comparisons and take advantage of its symmetry? Am I missing
something? Not sure if it makes it any faster though.
Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina
nikhil.l...@gmail.com
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo