Digipng Digipng - 1 year ago 97
R Question

How to select edge randomly from graph in R?

I have a regular graph and wanna delete randomly edge from graph. How to select edges randomly till I can delete?

g = sample_k_regular(10,3)

Answer Source

You can use the sample(x,n) function in base R along with delete_edges from igraph.

For example, if you want to delete 5 edges:

g = sample_k_regular(10,3)
g1 <- delete_edges(g,sample(E(g),5)) 

E(g) gets a list of edges that sample randomly samples from.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download