Return the nodes of an edge in the graph gr
selected at
random. Edges from other nodes can be ignored by passing their index(es) to
ignore_nodes_connected_to
. This is used in swapping edges by passing
the nodes for the first edge to be ignored in the selection of the second
edge.
random_edge_nodes(gr, ignore_nodes_connected_to = c())
gr | tidygraph graph object; must have the node attribute |
---|---|
ignore_nodes_connected_to | a vector of indices for the nodes whose edges to ignore |
a vector of two indices for the nodes of the edge selected; if no
edge was able to be selected, then integer(0)
is returned
set.seed(0) gr <- tidygraph::create_ring(5) gr <- tidygraph::mutate(gr, .idx = 1:dplyr::n()) random_edge_nodes(gr)#>#> [1] 1 5