Normalize node IDs in a graph to be consecutive integers starting from 1. This is useful for ensuring compatibility with graph algorithms that require sequential node IDs.
Value
A data frame with the same structure as graph_df, but with from
and to columns remapped to consecutive integer IDs starting from 1.
All other columns are preserved unchanged.
Details
This function:
Extracts all unique node IDs from both
fromandtocolumnsSorts them in ascending order
Remaps the original node IDs to sequential integers (1, 2, 3, ...)
Updates both
fromandtocolumns with the normalized IDs
Normalization is useful when:
Node IDs are non-consecutive (e.g., 1, 5, 10, 20)
Node IDs are non-numeric or contain gaps
Graph algorithms require sequential integer node IDs starting from 1
Note: This function only normalizes the node IDs; it does not modify the graph structure or any other attributes. The mapping preserves the relative ordering of nodes.
