# Create adjacency matrix
adj_matrix <- matrix(0, nrow = length(nodes), ncol = length(nodes),
dimnames = list(nodes, nodes))
# Fill matrix with 1s for directed edges
for (i in 1:nrow(edge_list)) {
from <- edge_list$df_IDs[i]
to <- edge_list$targets[i]
adj_matrix[from, to] <- 1
}Create Adjacency Matrix
We can now convert the edge list into an adjacency matrix.
An adjacency matrix records whether a relationship exists between each pair of nodes.
Add the following to your R script and run it:
The matrix now records the presence (1) or absence (0) of relationships between nodes.
NoteDirection
In this matrix, relationships are recorded as directed (from one node to another). In later steps, we will treat the network as undirected for analysis.
From this matrix, we can now calculate network measures such as degree, betweenness, and closeness.