Learn R Programming

Claddis (version 0.7.0)

split_out_subgraphs: Split adjacency matrix into subgraphs

Description

Given a graph represented by an adjacency matrix splits into all connected subgraphs.

Usage

split_out_subgraphs(adjacency_matrix)

Value

A list of all connected subgraphs represented as adjacency matri(ces).

Arguments

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).

Author

Graeme T. Lloyd graemetlloyd@gmail.com

Details

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).

Examples

Run this code

# 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)

Run the code above in your browser using DataLab