# conversion

From igraph v0.5.3
by Gabor Csardi

##### Convert a graph to an adjacency matrix or an edge list

Sometimes it is useful to have a standard representation of a graph, like an adjacency matrix or an edge list.

- Keywords
- graphs

##### Usage

```
get.adjacency(graph, type=c("both", "upper", "lower"),
attr=NULL, names=TRUE, binary=FALSE, sparse=FALSE)
get.edgelist(graph, names=TRUE)
```

##### Arguments

- graph
- The graph to convert.
- type
- Gives how to create the adjacency matrix for undirected
graphs. It is ignored for directed graphs. Possible values:
`upper`

: the upper right triangle of the matrix is used,`lower`

: the lower left triangle of the matrix i - attr
- Either
`NULL`

or a character string giving an edge attribute name. If`NULL`

a traditional adjacency matrix is returned. If not`NULL`

then the values of the given edge attribute are included in the adjacency m - names
- Logical constant.
For

`graph.adjacenct`

it gives whether to assign row and column names to the matrix. These are only assigned if the`name`

vertex attribute is present in the graph.for

`get.edgelist`

it - binary
- Logical, whether to return a binary matrix. This argument
is ignored if
`attr`

is not`NULL`

. - sparse
- Logical scalar, whether to create a sparse matrix. The
package must be installed for creating sparse matrices.`Matrix`

##### Details

`get.adjacency`

returns the adjacency matrix of a graph, a
regular Rmatrix if `sparse`

is `FALSE`

, or a sparse
matrix, as defined in the `Matrix`

`sparse`

if `TRUE`

.
`get.edgelist`

returns the list of edges in a graph.

##### Value

- A
`vcount(graph)`

by`vcount(graph)`

(usually) numeric matrix for`get.adjacency`

. (This can be huge!) Note that a non-numeric matrix might be returned if`attr`

is a non-numeric edge attribute.A

`ecount(graph)`

by 2 numeric matrix for`get.edgelist`

.

##### concept

- Edge list
- Adjacency list

##### See Also

##### Examples

```
g <- erdos.renyi.game(10, 2/10)
get.edgelist(g)
get.adjacency(g)
V(g)$name <- letters[1:vcount(g)]
get.adjacency(g)
E(g)$weight <- runif(ecount(g))
get.adjacency(g, attr="weight")
```

*Documentation reproduced from package igraph, version 0.5.3, License: GPL (>= 2)*

### Community examples

Looks like there are no examples yet.