[R-sig-Geo] construct neighbour list
Yilin Liu
Y.liu at mdx.ac.uk
Tue Jul 12 20:05:05 CEST 2005
Dear all,
Based on the neighbour list (denoted by X) obtained by "poly2nb", I tried to modify it by the following codes:
X1<-X
for(i in 1:108){
for( j in 1:num[i]){
if(num[i]!=0){
k<-k+1
X1[[i]][j]<-adj[k]
}}}
where num[i] is the number of neighours of region i, adj[k] is the region ID of the neighour.
A summary of X is:
Neighbour list object:
Number of regions: 108
Number of nonzero links: 536
Percentage nonzero weights: 4.595336
Average number of links: 4.962963
1 region with no links:
33
while a summary of X1 is:
Neighbour list object:
Number of regions: 108
Number of nonzero links: 0
Percentage nonzero weights: 0
Average number of links: 0
108 regions with no links:
This suggests no links have been set for X1.
However, X1[[match(i,r.id)]](where r.id<-attr(X1,"region.id"))
gives the right neighbours' ID for each region represented by "i".
How can solve this problem and get X1 with nonzero links.
Thanks.
More information about the R-sig-Geo
mailing list