subset.listw {spdep} | R Documentation |
Subset a spatial weights list
Description
The function subsets a spatial weights list, retaining objects for which the subset argument vector is TRUE. At present it will only subset non-general weights lists (that is those created by nb2listw
with glist=NULL
).
Usage
## S3 method for class 'listw'
subset(x, subset, zero.policy = attr(x, "zero.policy"), ...)
Arguments
x |
an object of class |
subset |
logical expression |
zero.policy |
default |
... |
generic function pass-through |
Value
The function returns an object of class listw
with component style
the same as the input object, component neighbours
a list of integer vectors containing neighbour region number ids (compacted to run from 1:number of regions in subset), and component weights
as the weights computed for neighbours
using style
. If no-neighbour observations are created by subsetting and zero.policy
in the input weights object was FALSE, it will be set to TRUE and a warning issued.
Author(s)
Roger Bivand Roger.Bivand@nhh.no
See Also
Examples
col.gal.nb <- read.gal(system.file("weights/columbus.gal", package="spData")[1])
to.be.dropped <- c(31, 34, 36, 39, 42, 46)
pre <- nb2listw(col.gal.nb)
print(pre)
post <- subset(pre, !(1:length(col.gal.nb) %in% to.be.dropped))
print(post)
columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE)
nb <- poly2nb(columbus)
lw <- nb2listw(nb, style="W")
attr(lw, "zero.policy")
(lwa <- subset(lw, 1:nrow(columbus) != c(21)))
attr(lwa, "zero.policy")
(lwb <- subset(lw, !(1:nrow(columbus) %in% c(21, 36, 39))))
attr(lwb, "zero.policy")