Skip to content
Prev 27720 / 29559 Next

poly2nb neighbour itself should be considered a neighbour

Dear All,

Many thanks for the proposed solutions, specially to Roger and Barry.

This was exactly what I was looking for.

I tested with a really simple polygon (see below), and it worked.

##
columbus <- sf::read_sf(system.file("etc/shapes/columbus.shp", package="spdep"))
columbus <- columbus %>% slice(1:2)?
# plot(columbus)?
?
colnn <- poly2nb(columbus)?
colnn[1]?
colnn[2]?
?
# Solution 1?
for(i in 1:length(colnn)){colnn[[i]]=as.integer(c(i,colnn[[i]]))}?
colnn[1]?
colnn[2]?
?
# Solution 2?
colnn <- include.self(colnn)?
colnn[1]?
colnn[2]?
?
lw <- nb2listw(neighbours = colnn, style="W", zero.policy=TRUE)

##

Best regards,
Robert