Skip to content
Prev 1096 / 29559 Next

adding links to neighbour lists

Hi folks,

I tried Roger's suggested method for adding extra links directly into a
neighbor list. To get it to work, I had to coerce the vector representing
the new link to be an integer vector instead of a numeric vector. Here's
what worked.

# Create an integer vector of the 2 regions (23 & 31) that need to be
connected.

ij <- as.integer(c(23,31))

# Update the neighbor list to add the symmetric link.

nb[[ij[1]]] <- sort(unique(c(nb[[ij[1]]], ij[2])))
nb[[ij[2]]] <- sort(unique(c(nb[[ij[2]]], ij[1])))

I just wanted to share that detail back to the list in case anyone else
wants to do this sort of data manipulation.

Steven J. Pierce
E-mail: pierces1 at msu.edu

-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Saturday, June 03, 2006 7:11 AM
To: Steven J. Pierce
Cc: r-sig-geo at stat.math.ethz.ch
Subject: Re: [R-sig-Geo] adding links to neighbour lists
On Fri, 2 Jun 2006, Steven J. Pierce wrote:

            
a
There is a drop.links() function but no add.links(). So yes, you could 
manipulate the list directly. If ij is a two element vector for the 
missing link:

nb[[ij[1]]] <- sort(unique(c(nb[[ij[1]]], ij[2])))
nb[[ij[2]]] <- sort(unique(c(nb[[ij[2]]], ij[1])))

should do it (untried). If there are more links, have a look at drop.links 
and see if you can adapt it.
object,
I think:

CITY.polys <- as(CITY.ZCTA.data, "SpatialPolygons")

should be enough, in time poly2nb() will do that internally.
CITY.ZCTA.data$centroid.y)
Could be:

coords.mat <- coordinates(CITY.ZCTA.data)

if the centroid.x|y values correspond to the polygon centroids.

Roger
graphics