[R-sig-Geo] How to attach customized row.names to poly2nb()

Xiang Ye x|@ngye @end|ng |rom bu||@|o@edu
Thu Jan 18 13:30:36 CET 2024


Dear community,

It should be a very simple question with a straightforward answer - so please forgive my foolishness.

By default, poly2nb() provides the neighbor list of a region in terms of numbers, for example:

library(spdep)
library(spDataLarge)

poly2nb(bristol_zones) -> bqueen
bqueen[1]

The output is
[cid:157ba602-300e-4f6b-8875-ea050def287c]
which is expected.

But often the case this is not convenient. So I want to provide a vector of names to label each region, and expect when I type bqueen[1], it can return something like a list of place names.

According to the help of poly2nb(), this is implemented by row.names(). However, it does not work:
[cid:be6a526c-5629-4c17-af44-972fb84f4a04]
It looks like the output neglects the argument of row.names.
How should I solve this issue?

Thanks in advance!


叶翔 YE, Xiang
THINKING SPATIALLY<http://www.linkedin.com/in/spatialyexiang>.
Ph.D. in Spatial Statistics

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20240118/b9f37558/attachment.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 15103 bytes
Desc: image.png
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20240118/b9f37558/attachment.png>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 19502 bytes
Desc: image.png
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20240118/b9f37558/attachment-0001.png>


More information about the R-sig-Geo mailing list