iterate | R Documentation |
The iterate family of functions allow you to call the same modification function on a graph until some condition is met. This can be used to create simple simulations in a tidygraph friendly API
iterate_n(.data, n, .f, ...)
iterate_while(.data, cnd, .f, ..., max_n = NULL)
.data |
A |
n |
The number of times to iterate |
.f |
A function taking in a |
... |
Further arguments passed on to |
cnd |
A condition that must evaluate to |
max_n |
The maximum number of iterations in case |
A tbl_graph
object
# Gradually remove edges from the least connected nodes while avoiding
# isolates
create_notable('zachary') |>
iterate_n(20, function(gr) {
gr |>
activate(nodes) |>
mutate(deg = centrality_degree(), rank = order(deg)) |>
activate(edges) |>
slice(
-which(edge_is_incident(.N()$rank == sum(.N()$deg == 1) + 1))[1]
)
})
# Remove a random edge until the graph is split in two
create_notable('zachary') |>
iterate_while(graph_component_count() == 1, function(gr) {
gr |>
activate(edges) |>
slice(-sample(graph_size(), 1))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.