[R] spdep::poly2nb problem
Philip A. Viton
viton.1 at osu.edu
Sat May 7 18:53:18 CEST 2011
I downloaded a US states+territories shapefile from
http://www.weather.gov/geodata/catalog/national/html/us-state.htm
and unzipped it into my working directory.
Then in R (version 12.2.0 for ms-win32):
library(rgdal) # Version: 0.6-28
library(spdep) # Version: 0.5-24 (loads sp: Version: 0.9-72)
# read in the data
states<-readOGR(".","s_01de10")
summary(states)
# now create a neighbors list
states_nb<-poly2nb(states)
# create a 0/1 matrix of the neighbors
nb_mat<-nb2mat(states_nb,style="B",zero.policy=TRUE)
# add names
nms<-as.character(states$NAMES)
# set the matrix names
dimnames(nb_mat)<-list(nms,nms)
# now see which states have no neighbors
rowSums(nb_mat)
# it turns out that Florida seems to have zero neighbors.
I then repeated it with
states_nb<-poly2nb(states,useC=FALSE)
and this time -- the computation takes a lot longer, of course
--- Florida has 2 neighbors (correctly: AL and GA).
Can anyone tell me what's going wrong here?
Thanks!
------------------------
Philip A. Viton
City Planning, Ohio State University
275 West Woodruff Avenue, Columbus OH 43210
viton.1 at osu.edu
More information about the R-help
mailing list