View source: R/split_out_subgraphs.R
split_out_subgraphs | R Documentation |
Given a graph represented by an adjacency matrix splits into all connected subgraphs.
split_out_subgraphs(adjacency_matrix)
adjacency_matrix |
An adjacency matrix where the diagonal is zeroes and the off-diagonal either ones (if the two vertices are directly connected) or zeroes (if not directly connected). |
This functions take any undirected graph (connected or unconnected) represented as an adjacency matrix and identifies all connected subgraphs and returns these as a list of adjacency matr(ices).
A list of all connected subgraphs represented as adjacency matri(ces).
Graeme T. Lloyd graemetlloyd@gmail.com
# Create an adjacency matrix representing an unconnected graph:
adjacency_matrix <- matrix(
data = c(
0, 0, 0, 1, 1, 0,
0, 0, 1, 0, 0, 1,
0, 1, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 1, 1, 0, 0, 0
),
ncol = 6,
byrow = TRUE,
dimnames = list(LETTERS[1:6], LETTERS[1:6])
)
# Check graph is connected:
split_out_subgraphs(adjacency_matrix = adjacency_matrix)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.