Skip to content

a problem with creating a neighbours list

2 messages · stevenhuyi, Roger Bivand

#
Hi everyone,
I have a  simple problem, which I know will have a simple solution, but I
just can't tackle it. 

I have a shapefile with regions, including an attribute containing a
regional id. I used the following R script to create a neighbours list:

anhui <- readShapePoly("endemic.shp")
zzz<- poly2nb(anhui,row.names=anhui$COUNTY_ID)
nb2INLA("anhui.graph", zzz)
Anhui.adj <- paste(getwd(),"/Anhui.graph",sep="")

However, the Anhui.adj file is just as follows
31
1 5 3 4 5 6 7
2 2 3 7
3 3 1 2 7
4 2 1 5
...

the id number is not the original id number in my shapefile (which are
actually 1289, 1290,...). Is there a way to get a neighbours list that is
created using the original id number? Thanks for your help.

Yi




--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/a-problem-with-creating-a-neighbours-list-tp7588325.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
On Tue, 26 May 2015, stevenhuyi wrote:

            
Please always state which package functions come from, here maptools:
and here spdep:
This is what spdep::nb2INLA() provides - why would you need your COUNTY_ID 
character value? In INLA, you usually would set idx to 1:n, not character 
ID values, I think?

Roger