This is an extension of the question posted previously: How to split an igraph into connected subgraphs?
I'll use the same example as the previous question
library(igraph)
g <- simplify(
graph.compose(
graph.ring(10),
graph.star(5, mode = "undirected")
)
) + edge("7", "8")
The original user wanted to separate the network into the connected components. I would like to get a selection of the connected components based on the nodes, i.e. I want the networks containing node 9 and 2.
I think it could be done with decompose.graph(g)
but I'm not sure how to put the two subgraphs back together. I need something like compose.graph(sub_g1, sub_g2)
.