R: Extract connected graphs -


i've undirected graph composed of ~300 nodes. graph composed of multiple connected graphs (example below undirected graph composed of 5 connected graph). using r, how can extract each connected sub-graph, , node , edge count. graph represented two-column data.frame:

node1 node2 node1 node3 node2 node5 ...   

with example below, expected result be

subgraph nodecount edgecount 1        2         1 2        4         3 3        2         1 4        2         1 5        2         1 

thanks

enter image description here

you can this:

library(igraph) set.seed(1) g <- simplify(graph.compose(graph.ring(10), graph.star(5, mode = "undirected"))) + edge("7", "8") dg <- decompose.graph(g) t(sapply(seq_along(dg), function(x) c(subgraph = x, nodecount = vcount(dg[[x]]), edgecount = ecount(dg[[x]])))) #      subgraph nodecount edgecount # [1,]        1         7        12 # [2,]        2         2         1 # [3,]        3         1         0 

the example graph looks (plot(g)):

enter image description here


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -