Sample a random but connected sub-component of a graph

dodgr_sample(graph, nverts = 1000)

Arguments

graph

A flat table of graph edges. Must contain columns labelled from and to, or start and stop. May also contain similarly labelled columns of spatial coordinates (for example from_x) or stop_lon).

nverts

Number of vertices to sample

Value

A connected sub-component of graph

Note

Graphs may occassionally have nverts + 1 vertices, rather than the requested nverts.

Examples

graph <- weight_streetnet (hampi) nrow (graph) # 5,742
#> [1] 5845
graph <- dodgr_sample (graph, nverts = 200) nrow (graph) # generally around 400 edges
#> [1] 409
nrow (dodgr_vertices (graph)) # 200
#> [1] 200