create_relation_matrix: Create or Convert to Adjacency Matrix

View source: R/create_relation_matrix.R

create_relation_matrixR Documentation

Create or Convert to Adjacency Matrix

Description

Creates a new adjacency matrix or converts existing data to an adjacency matrix format suitable for ISM analysis.

Usage

create_relation_matrix(input, from = 1, to = 2, nodes = NULL)

Arguments

input

Input data. Accepts:

  • Integer n: creates an n x n zero matrix

  • Matrix: validates and returns (or converts from edge list)

  • Data frame: converts from edge list format

from

Column position or name for source nodes (when input is an edge list). Default is 1.

to

Column position or name for target nodes (when input is an edge list). Default is 2.

nodes

Optional character vector of predefined node names. Ensures matrix completeness when converting from edge lists.

Details

This function provides a unified interface for creating adjacency matrices in ISM analysis. It handles three common scenarios:

  1. Creating an empty matrix of specified size for manual population

  2. Converting edge list data (data.frame or matrix) to adjacency format

  3. Validating existing adjacency matrices

Value

A square adjacency matrix with node labels as dimnames. A value of 1 at position (i,j) indicates a directed relationship from element i to element j.

See Also

convert_to_matrix for the underlying conversion logic, compute_reachability for computing reachability matrices.

Examples

# Create a 3x3 zero matrix
create_relation_matrix(3)

# Create with custom node labels
create_relation_matrix(3, nodes = c("A", "B", "C"))

# Convert edge list data.frame
edge_df <- data.frame(source = c("A", "B"), target = c("B", "C"))
create_relation_matrix(edge_df, from = "source", to = "target",
                       nodes = LETTERS[1:4])

# Validate existing matrix
existing_mat <- matrix(c(0, 1, 1, 0), nrow = 2)
create_relation_matrix(existing_mat)

ISMtools documentation built on March 13, 2026, 1:06 a.m.