Skip to contents

Sample a random but connected sub-component of a graph

Usage

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 occasionally have nverts + 1 vertices, rather than the requested nverts.

Examples

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