The union of two or more graphs are created. The graphs are assumed to have disjoint vertex sets.
Details
disjoint_union() creates a union of two or more disjoint graphs.
Thus first the vertices in the second, third, etc. graphs are relabeled to
have completely disjoint graphs. Then a simple union is created. This
function can also be used via the %du% operator.
disjoint_union() handles graph, vertex and edge attributes. In
particular, it merges vertex and edge attributes using the vctrs::vec_c()
function. For graphs that lack some vertex/edge attribute, the corresponding
values in the new graph are set to a missing value (NA for scalar attributes,
NULL for list attributes). Graph attributes are simply
copied to the result. If this would result a name clash, then they are
renamed by adding suffixes: _1, _2, etc.
Note that if both graphs have vertex names (i.e. a name vertex
attribute), then the concatenated vertex names might be non-unique in the
result. A warning is given if this happens.
An error is generated if some input graphs are directed and others are undirected.
See also
Other functions for manipulating graph structure:
+.igraph(),
add_edges(),
add_vertices(),
complementer(),
compose(),
connect(),
contract(),
delete_edges(),
delete_vertices(),
difference(),
difference.igraph(),
edge(),
igraph-minus,
intersection(),
intersection.igraph(),
path(),
permute(),
rep.igraph(),
reverse_edges(),
simplify(),
transitive_closure(),
union(),
union.igraph(),
vertex()
Author
Gabor Csardi csardi.gabor@gmail.com
Examples
## A star and a ring
g1 <- make_star(10, mode = "undirected")
V(g1)$name <- letters[1:10]
g2 <- make_ring(10)
V(g2)$name <- letters[11:20]
print_all(g1 %du% g2)
#> ── <igraph> ───────────────────────────────────────────────────────── 39a91c7 ──
#> ℹ undirected · named
#> ℹ 20 vertices · 19 edges
#>
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph: name_1 <chr>, name_2 <chr>, mode <chr>, center <dbl>, mutual <lgl>, circular <lgl>
#> → vertex: name <chr>
#>
#> ── Edges (vertex names) ────────────────────────────────────────────────────────
#> [1] a ─ b a ─ c a ─ d a ─ e a ─ f a ─ g a ─ h a ─ i a ─ j k ─ l
#> [11] l ─ m m ─ n n ─ o o ─ p p ─ q q ─ r r ─ s s ─ t k ─ t
