Convert from node and edge graph representation to a sparse adjacency matrix representation
graph2Matrix(edges, nodes, symmetric = TRUE)
A data frame with at least the columns "from" and "to"
referring to edges between ids in the nodes
data frame. If the data
frame includes a numeric "size" variable then graph is assumed to be weighted
and the corresponding matrix entries are set to the size values.
Optional data frame with at least a column named "id"
corresponding to the from
and to
node ids in the edges
argument. The size of the matrix is determined by number of rows in the data
frame. If nodes
is missing it will be inferred from the edges
. If
nodes
has a "label" column, the matrix row and column names will be set
to the corresponding node labels.
Set to FALSE
for directed graphs, or leave as TRUE
for undirected graphs.
A sparse matrix
# NOT RUN {
data(LeMis)
M <- graph2Matrix(LeMis$edges, LeMis$nodes)
G <- matrix2graph(M)
# }
Run the code above in your browser using DataLab