Closed JosiahParry closed 1 year ago
With this push, I see:
> cnts <- tigris::counties(cb = TRUE)
Retrieving data for the year 2020
|======================================================================| 100%
> geo <- sf::st_centroid(cnts)
Warning message:
In st_centroid.sf(cnts) :
st_centroid assumes attributes are constant over geometries of x
> k = 8
> ks <- spdep::knearneigh(geo, k = k)
> nb <- spdep::knn2nb(ks, sym = FALSE)
> table(sapply(nb, length))
8
3234
> table(sapply(spdep::nbdists(nb, geo), length))
8
3234
There was a missing simplify=FALSE
in the aggregate()
call - for ragged neighbour counts a list was returned, but for knn (equal counts) a matrix where simplify=
took its default TRUE
value. Please check and report back, thanks again for your input!
we've all been bitten by simplify = FALSE
! It's fixed! Thanks :)
I'm unsure where this issue is being derived from. Note the warning message from aggregate.
Each element of the resultant list should have 8 values since there are 8 neighbors. However, there is only 1 for each.
Note the reprex below.
Sorry I can't be more detailed I'm actually stumped!
Created on 2022-10-27 with reprex v2.0.2