(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

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to