add_node_ids: Add node ID numbers to an edge list

View source: R/node_edge_list.R

add_node_idsR Documentation

Add node ID numbers to an edge list

Description

Edge lists can contain identification numbers (integers) for each node. Because each row in the edge list data frame contains a "From" node and a "To" node, two columns of node IDs are added, one for "From" and one for "To".

Usage

add_node_ids(
  edge_list,
  from = "From",
  to = "To",
  node_id = "node_id",
  first_node = 0
)

Arguments

edge_list

the edge list to which node ID numbers are to be added

from

the name of the column containing source nodes. (Default is "From".)

to

the name of the column containing destination nodes. (Default is "To".)

node_id

the root of the column name for node IDs. (Default is "node_ID".) See details.

first_node

the ID number of the first node. (Default is 0.)

Details

The column names for the "From" and "To" nodes are created by paste-ing the value of the from and to arguments with the value of the node_id argument.

Value

edge_list with two additional columns containing From and To node ID numbers.

Examples

library(matsbyname)
library(tidyr)
sutmats <- UKEnergy2000mats %>% spread(key = matrix.name, value = matrix)
# Suppress adding node IDs
elDF <- edge_list(sutmats, node_id = NULL)$`Edge list`[[1]]
add_node_ids(elDF)

MatthewHeun/Recca documentation built on Feb. 9, 2024, 6:18 p.m.