[R-sig-Geo] exporting neighbor list to a text file...
Alok K Bohara, PhD
bohara at unm.edu
Thu Aug 16 17:47:07 CEST 2012
(I am new to this group.) I have a two-part question. I have a shape
file for the US states (excluding Alaska and Hawaii)
I am trying to export (or save) the nearest neighbor list to a csv or
text file.
This is what I did
***
USs <- readShapeSpatial("usa")
# Creating Neighbor List
USs.nb <- poly2nb(USs)
IDs <- row.names(as(USs, "data.frame"))
NeighMap <- nb2gra(USs.nb)
NeighList <- get.neighbor(NeighMap, IDs)
summary(NeighList)
(IDs extracted above begins from 0, 1, 2,... 50).
***
Is there any way I could save/export the neigbor list as follows where
the first line is the number of cells/states (49) and the rest of the
lines as whown below:
49
1 3 4 18 21
2 2 5 4
3 2 8 12 15 32
.
.
49 3 9 11
etc...
****
Thanks.
Sincerely,
Alok Bohara
UNM
More information about the R-sig-Geo
mailing list