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.
Related documentation in the C library
create(), empty(), vcount(), famous(), simplify(), is_simple()
See also
Other deterministic constructors:
graph_from_atlas(),
graph_from_literal(),
make_(),
make_chordal_ring(),
make_circulant(),
make_empty_graph(),
make_full_citation_graph(),
make_full_graph(),
make_full_multipartite(),
make_graph(),
make_lattice(),
make_ring(),
make_star(),
make_tree(),
make_turan(),
make_wheel()
Examples
el <- matrix(c("foo", "bar", "bar", "foobar"), nc = 2, byrow = TRUE)
graph_from_edgelist(el)
#> ── <igraph> ───────────────────────────────────────────────────────── d6164ce ──
#> ℹ directed · named
#> ℹ 3 vertices · 2 edges
#>
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → vertex: name <chr>
#>
#> ── Edges (vertex names) ────────────────────────────────────────────────────────
#> [1] foo → bar bar → foobar
# Create a ring by hand
graph_from_edgelist(cbind(1:10, c(2:10, 1)))
#> ── <igraph> ───────────────────────────────────────────────────────── ab35520 ──
#> ℹ directed
#> ℹ 10 vertices · 10 edges
#>
#> ── Edges ───────────────────────────────────────────────────────────────────────
#> [1] 1 → 2 2 → 3 3 → 4 4 → 5 5 → 6 6 → 7 7 → 8 8 → 9 9 → 10
#> [10] 10 → 1
