Skip to content
Prev 29334 / 29559 Next

How to attach customized row.names to poly2nb()

Please never attach screenshots, nobody can copy/paste the code shown in them. Thus:

library(spdep)
library(spDataLarge)
data(bristol_zones)
bqueen <- poly2nb(bristol_zones, row.names=bristol_zones$name)

However, updating to also suppport sf removed the facility of setting through the row.names= argument:

attr(bqueen, "region.id")[bqueen[[1]]]
# [1] "2"  "39" "44" "50" "86" "94"

https://github.com/r-spatial/spdep/blob/b815397c2ce0d58b3b4ca0c36bba7b5c3abbbcc2/R/poly2nb.R#L16-L20

poly2nb(as(bristol_zones, "Spatial"), row.names = bristol_zones$name)
attr(bqueen, "region.id")[bqueen[[1]]]
# [1] "Bath and North East Somerset 003" "Bristol 038"
# [3] "Bristol 043"                      "Bristol 049"
# [5] "South Gloucestershire 024"        "South Gloucestershire 032"

I've raised this issue https://github.com/r-spatial/spdep/issues/143 so this should work again at the next release.

Roger
--
Roger Bivand
Emeritus Professor
Norwegian School of Economics
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway
Roger.Bivand at nhh.no
Message-ID: <SV0P279MB0475D300F82158D574E9B576EE712@SV0P279MB0475.NORP279.PROD.OUTLOOK.COM>
In-Reply-To: <SA1PR15MB63974D3217B0206F1F79FBA0B0712@SA1PR15MB6397.namprd15.prod.outlook.com>