Skip to content
Prev 7211 / 29559 Next

create nb object

On Wed, 16 Dec 2009, Pete Larson wrote:

            
Create a matrix of coordinates, if not using sp classes, for example:

xy <- cbind(df$x, df$y)

or if your data frame is a SpatialPointsDataFrame, just:

xy <- coordinates(obj)

Then your choice of dnearneigh(), knn2nb(knearneigh()), graph2nb() with 
three graph variants, tri2nb() for a Delaunay triangulation. The first two 
of these also take a longlat= argument in case your coordinates are 
geographical, not projected. Triangulation and graph-based methods need 
planar coordinates, so you would have to project them first.

Hope this helps,

Roger