[R-sig-Geo] create nb object
Roger Bivand
Roger.Bivand at nhh.no
Thu Dec 17 09:14:38 CET 2009
On Wed, 16 Dec 2009, Pete Larson wrote:
> Hello all,
>
> I have a data frame with lat and lon coordinates for some sample areas (not a
> grid) .
>
> I was to create an nb object that I can use with spdep but am unsure as to
> how to convert it.
>
> Does anybody have any ideas?
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
>
> Thanks,
>
>
> Pete
>>
>>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list