Hello Mathematica friends!
I've got a network with thousands of edges and vertices, but not all in one connected component. I'm trying to extract specific connected components from the network, and assign them as new variables.
g = Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 1 \[UndirectedEdge] 3, 4 \[UndirectedEdge] 5, 7 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 6, 5 \[UndirectedEdge] 7, 7 \[UndirectedEdge] 8}]
I know it's a disconnected component because of:
WeaklyConnectedGraphQ[g]
False
I know there are two components:
Length[WeaklyConnectedComponents[g]]
2
I know how many vertices are in each component:
Length /@ WeaklyConnectedComponents[g]
{5, 3}
And I know what vertices are in each component:
WeaklyConnectedComponents[g]
{{7, 6, 5, 8, 4}, {3, 2, 1}}
What I don't know is how to a assign on of these components to a new variable to then proceed with analysis on just a single connected component?