
Transform the edge list representation of a graph into an adjacency matrix
Source:R/utils.R
adjacency_from_edge_list.RdThis helper is useful for generating the inputs for functions that expect preference graphs.
See also
maximum_mutual_information_nominal() and maximum_mutual_information_nominal_heuristic() for functions that accept an adj_matrix.
maximum_mutual_information_nominal_supervised() for the supervised analogue that also accepts an adj_matrix.
Examples
levels <- c("A", "B", "C", "D")
edges <- list(c("A", "C"), c("D", "B"))
# Include the pairings from `edges`:
adjacency_from_edge_list(levels, allow = edges)
#> A B C D
#> A 0 0 1 0
#> B 0 0 0 1
#> C 1 0 0 0
#> D 0 1 0 0
# Or exclude them:
adjacency_from_edge_list(levels, disallow = edges)
#> A B C D
#> A 1 1 0 1
#> B 1 1 1 0
#> C 0 1 1 1
#> D 1 0 1 1