graph-operators-by-name

0th

Percentile

Graph operators based on symbolic vertex names

Normally igraph operators are based on internal igraph vertex ids. This function works with vertex names instead.

Keywords
graphs
Usage
graph.intersection.by.name(g1, g2, keep.x.vertices = FALSE,
      keep.x.vertex.attributes = FALSE,
      keep.x.edge.attributes = FALSE)
graph.union.by.name(g1, g2)
graph.difference.by.name(g1, g2, keep.x.vertex.attributes = FALSE,
      keep.x.edge.attributes = FALSE)
Arguments
g1,g2
The input graphs, they should be both directed or both undirected.
keep.x.vertices
Logical scalar, whether to keep all the vertices of g1, even if they do not appear in g2.
keep.x.vertex.attributes
Logical scalar, whether to keep all vertex attributes of the g1, even if they do not appear in g2.
keep.x.edge.attributes
Logical scalar, whether to keep edge attributes of g1, even if they do not appear in g2.
Details

These functions treat the graphs as sets of ordered (if they are directed), or unordered (if they are undirected) pairs of symbolic vertex names and perform set operations on them.

Value

  • A new graph object.

concept

Graph operators

See Also

graph.union, link{graph.intersection} and link{graph.difference} for the functions that are based on vertex ids.

Aliases
  • graph.intersection.by.name
  • graph.union.by.name
  • graph.difference.by.name
Examples
# Print attributes as well
igraph.options(print.vertex.attributes=TRUE,
               print.edge.attributes=TRUE)

# Creating a wheel graph
g1 <- graph.ring(10)
V(g1)$name <- letters[1:vcount(g1)]
g2 <- graph.star(11, mode="undirected")
V(g2)$name <- c("z", letters[1:vcount(g1)])
g <- graph.union.by.name(g1, g2)
if (interactive()) {
  plot(g, layout=layout.kamada.kawai, vertex.label=V(g)$name)
}
g

# Some more examples
g1 <- graph.formula(a-b-c)
V(g1)$v.attr=c(1,2,3)
E(g1)$e.attr=c(5,7)
g2 <- graph.formula(b-c-d)

# Test the functions
graph.intersection.by.name(g1,g2) # Vertices are intersected as well
graph.union.by.name(g1,g2)        # Vertices are unioned as well
graph.difference.by.name(g1,g2)   # Vertices from x (g1) are used

# graph.intersection.by.name() has some extra parameters
graph.intersection.by.name(g1,g2,
    keep.x.vertices          = TRUE) # Keep all x vertices (only intersect edges)

graph.intersection.by.name(g1,g2,
    keep.x.vertices          = FALSE, # Keep all x vertices (only intersect edges)
    keep.x.vertex.attributes = TRUE, # Don't throw away V(g1) attributes
    keep.x.edge.attributes   = TRUE) # Don't throw away E(g1) attributes

# graph.difference.by.name() has some extra parameters
graph.difference.by.name(g1,g2,
    keep.x.vertex.attributes = TRUE, # Don't throw away V(g1) attributes
    keep.x.edge.attributes   = TRUE) # Don't throw away E(g1) attributes
Documentation reproduced from package igraph, version 0.6.5-2, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.