For precincts which have no adjacent precincts, this suggests the nearest precinct as a friend to add. This is useful for when a small number of precincts are disconnected from the remainder of the geography, such as an island.

suggest_neighbors(shp, adj, idx, neighbors = 1)

Arguments

shp

an sf shapefile

adj

an adjacency list

idx

Optional. Which indices to suggest neighbors for. If blank, suggests for those with no neighbors.

neighbors

number of neighbors to suggest

Value

tibble with two columns of suggested rows of shp to connect in adj

Examples

library(dplyr)
data(va18sub)
va18sub <- va18sub |> filter(!VTDST %in% c('000516', '000510', '000505', '000518'))
adj <- adjacency(va18sub)
suggests <- suggest_neighbors(va18sub, adj)
adj <- adj |> add_edge(v1 = suggests$x, v2 = suggests$y)