Skip to contents

graph_from_edgelist() creates a graph from an edge list. Its argument is a two-column matrix, each row defines one edge. If it is a numeric matrix then its elements are interpreted as vertex ids. If it is a character matrix then it is interpreted as symbolic vertex names and a vertex id will be assigned to each name, and also a name vertex attribute will be added.

Usage

graph_from_edgelist(el, directed = TRUE)

from_edgelist(...)

Arguments

el

The edge list, a two column matrix, character or numeric.

directed

Whether to create a directed graph.

...

Passed to graph_from_edgelist().

Value

An igraph graph.

Examples

el <- matrix(c("foo", "bar", "bar", "foobar"), nc = 2, byrow = TRUE)
graph_from_edgelist(el)
#> IGRAPH 214b267 DN-- 3 2 -- 
#> + attr: name (v/c)
#> + edges from 214b267 (vertex names):
#> [1] foo->bar    bar->foobar

# Create a ring by hand
graph_from_edgelist(cbind(1:10, c(2:10, 1)))
#> IGRAPH 24046d8 D--- 10 10 -- 
#> + edges from 24046d8:
#>  [1]  1-> 2  2-> 3  3-> 4  4-> 5  5-> 6  6-> 7  7-> 8  8-> 9  9->10 10-> 1