igraph (version 0.4.5)

as.directed: Convert between directed and undirected graphs

Description

as.directed converts an undirected graph to directed, as.undirected is the opposite, it converts a directed graph to undirected.

Usage

as.directed(graph, mode = "mutual") 
as.undirected(graph, mode = "collapse")

Arguments

graph
The graph to convert.
mode
Character constant, defines the conversion algorithm. For as.directed it can be mutual or arbitrary. For as.undirected it can be each or collapse. See details below.

Value

  • A new graph object.

code

as.undirected

itemize

  • each

item

collapse

Details

Conversion algorithms for as.directed:
  • arbitrary
{The number of edges in the graph stays the same, an arbitrarily directed edge is created for each undirected edge.} mutual{Two directed edges are created for each undirected edge, one in each direction.}

See Also

simplify for removing multiple and/or loop edges from a graph.

Examples

Run this code
g <- graph.ring(10)
as.directed(g, "mutual")
g2 <- graph.star(10)
as.undirected(g)

Run the code above in your browser using DataCamp Workspace