as.directed {igraph} | R Documentation

## 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 = c("mutual", "arbitrary"))
    as.undirected(graph, mode = c("collapse", "each"))

### 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.

### 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.

Conversion algorithms for `as.undirected`:

each
  The number of edges remains constant, an undirected edge is created for each directed one, this version might create graphs with multiple edges.
collapse
  One undirected edge will be created for each pair of vertices which are connected with at least one directed edge, no multiple edges will be created.

### Value

A new graph object.

### Author(s)

Gabor Csardi csardi@rmki.kfki.hu

### See Also

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

### Examples

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

[Package igraph version 0.5.2 Index]