Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Returning Neighbor Attributes Using Queen Contiguity [closed]

$
0
0

I am trying to build a function to return the value(s) of a neighboring state(s) FIPS for any given state FIPS. So far I've been able to create a spatial weights matrix using the spdep::poly2nb() function, but this only returns an integer for the number of neighbors whereas I was hoping to get a vector/list. For example, f(08) for Florida would return c(09,01) for Mississippi and Alabama.

Is anyone familiar of a way to do this using queen contiguity?

> head(florida)
Simple feature collection with 6 features and 7 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: -82.77634 ymin: 28.30456 xmax: -80.73282 ymax: 29.42705
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
  STFIPS CTFIPS   STATE   COUNTY VERSION Shape_Leng Shape_Area                       geometry
1     12  12069 Florida     Lake      05   3.580470 0.27591000 MULTIPOLYGON (((-81.6419 29...
2     12  12119 Florida   Sumter      05   2.157470 0.13878814 MULTIPOLYGON (((-81.95419 2...
3     12  12117 Florida Seminole      05   1.542572 0.08248891 MULTIPOLYGON (((-80.98725 2...
4     12  12127 Florida  Volusia      05  11.160615 0.27614808 MULTIPOLYGON (((-81.10706 2...
5     12  12095 Florida   Orange      05   2.709400 0.23973772 MULTIPOLYGON (((-80.88002 2...
6     12  12017 Florida   Citrus      05  11.969303 0.14907229 MULTIPOLYGON (((-82.6456 28...

> nb.FOQ = poly2nb(florida, queen = TRUE, row.names = florida$CTFIPS)
> nb.FOQ
Neighbour list object:
Number of regions: 67 
Number of nonzero links: 312 
Percentage nonzero weights: 6.950323 
Average number of links: 4.656716 
1 region with no links:
31

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>