View source: R/convert_inputs.R
| convert_to_matrix | R Documentation |
Converts various input formats (data.frame, matrix) to a standard adjacency matrix suitable for ISM analysis. Performs validation and provides warnings for potential issues.
convert_to_matrix(x, from = 1, to = 2, nodes = NULL, validate = TRUE)
x |
Input data. Can be:
|
from |
Column name or index for source nodes (if x is a data.frame). Default is 1. |
to |
Column name or index for target nodes (if x is a data.frame). Default is 2. |
nodes |
Optional character vector of predefined node names. If provided, ensures the resulting matrix includes all specified nodes. |
validate |
Logical. If |
This function provides flexible input handling for ISM analysis. It can convert edge lists (either as data frames or two-column matrices) into adjacency matrices, or validate and return existing adjacency matrices.
When validate = TRUE, the function checks:
Square matrices contain only 0s and 1s (or logical values)
Edge list nodes exist in the predefined node list (if provided)
Column names exist in data frames
A square numeric adjacency matrix with node names as row and column names. A value of 1 at position (i,j) indicates a directed edge from node i to node j.
create_relation_matrix for a higher-level interface,
ssim_to_matrix for SSIM conversion,
compute_reachability for computing reachability matrices.
# From data frame edge list
edge_df <- data.frame(source = c("A", "B"), target = c("B", "C"))
convert_to_matrix(edge_df, from = "source", to = "target")
# From matrix edge list
edge_mat <- matrix(c("A", "B", "B", "C"), ncol = 2, byrow = TRUE)
convert_to_matrix(edge_mat)
# Existing adjacency matrix (validated and returned)
adj_mat <- matrix(c(0, 1, 0, 0,
0, 0, 1, 1,
0, 0, 0, 0,
0, 0, 0, 0), nrow = 4, byrow = TRUE)
convert_to_matrix(adj_mat)
# With predefined nodes (ensures all nodes are included)
edge_df <- data.frame(source = "A", target = "B")
convert_to_matrix(edge_df, from = "source", to = "target",
nodes = c("A", "B", "C", "D"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.