Find the multiple or loop edges in a graph
A loop edge is an edge from a vertex to itself. An edge is a multiple edge if it has exactly the same head and tail vertices as another edge. A graph without multiple and loop edges is called a simple graph.
is.loop(graph, eids=E(graph)) is.multiple(graph, eids=E(graph)) count.multiple(graph, eids=E(graph))
- The input graph.
- The edges to which the query is restricted. By default this is all edges in the graph.
Note that the semantics for
count.multiple is different.
for all occurences of a multiple edge except for one. Ie. if there are
i-j edges in the graph then
TRUE for only two of them while
See the examples for getting rid of multiple edges while keeping their original multiplicity as an edge attribute.
is.multiplereturn a logical vector.
count.multiplereturns a numeric vector.
simplify to eliminate loop and multiple edges.
# Loops g <- graph( c(0,0,1,1,2,2,3,4) ) is.loop(g) # Multiple edges g <- barabasi.game(10, m=3) is.multiple(g) count.multiple(g) is.multiple(simplify(g)) all(count.multiple(simplify(g)) == 1) # Direction of the edge is important is.multiple(graph( c(0,1, 1,0) )) is.multiple(graph( c(0,1, 1,0), dir=FALSE )) # Remove multiple edges but keep multiplicity g <- barabasi.game(10, m=3) E(g)$weight <- count.multiple(g) g <- simplify(g) any(is.multiple(g)) E(g)$weight