简体   繁体   中英

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?

library(igraph)
g = sample_k_regular(10,3)

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:

library(igraph)
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM