Create Edge List

From the prepared dataset (Masterdata), we can now extract the relationships between nodes.

Edges (connections) are created as pairs of nodes, forming an edge list.

Copy and paste the following into your R script, ensure the cursor is at the start of the chunk, and click run.

# Create edge list from Masterdata
edge_list <- Masterdata %>%
  rowwise() %>%
  mutate(targets = strsplit(relations, ";\\s*")) %>%
  unnest(targets) %>%
  filter(targets != "") %>%
  distinct(df_IDs, targets)

# Get all unique nodes
nodes <- sort(unique(c(Masterdata$df_IDs, edge_list$targets)))

The object edge_list now contains all relationships as pairs of nodes.

NoteEdge list

An edge list is a table where each row represents a connection between two nodes (a dyad). This is a common format used for network analysis in R.

From this structure, we can now create a matrix representation of the network.