Convert from node and edge graph representation to a sparse adjacency matrix representation

Share:

Description

Convert from node and edge graph representation to a sparse adjacency matrix representation

Usage

1
graph2Matrix(edges, nodes, symmetric = TRUE)

Arguments

edges

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.

nodes

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.

symmetric

Set to FALSE for directed graphs, or leave as TRUE for undirected graphs.

Value

A sparse matrix

See Also

graphjs, graph2Matrix

Examples

1
2
3
data(LeMis)
M <- graph2Matrix(LeMis$edges, LeMis$nodes)
G <- matrix2graph(M)