[R-sig-Geo] cell2nb

Nikhil Kaza nikhil.list at gmail.com
Mon Jun 21 21:28:29 CEST 2010


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.list at gmail.com



More information about the R-sig-Geo mailing list