# as_adjacency_matrix

From igraph v1.0.0
by Gabor Csardi

##### Convert a graph to an adjacency matrix

Sometimes it is useful to work with a standard representation of a graph, like an adjacency matrix.

##### Usage

```
as_adjacency_matrix(graph, type = c("both", "upper", "lower"), attr = NULL,
edges = FALSE, names = TRUE, sparse = igraph_opt("sparsematrices"))
```as_adj(graph, type = c("both", "upper", "lower"), attr = NULL,
edges = FALSE, names = TRUE, sparse = igraph_opt("sparsematrices"))

##### 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 is used. - 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 matrix. If th - edges
- Logical scalar, whether to return the edge ids in the matrix. For non-existant edges zero is returned.
- names
- Logical constant, whether to assign row and column names
to the matrix. These are only assigned if the
`name`

vertex attribute is present in the graph. - sparse
- Logical scalar, whether to create a sparse matrix. The
package must be installed for creating sparse matrices.`Matrix`

##### Details

`as_adjacency_matrix`

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

is `FALSE`

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

`sparse`

if
`TRUE`

.

##### Value

- A
`vcount(graph)`

by`vcount(graph)`

(usually) numeric matrix.

##### See Also

##### Examples

```
g <- sample_gnp(10, 2/10)
as_adjacency_matrix(g)
V(g)$name <- letters[1:vcount(g)]
as_adjacency_matrix(g)
E(g)$weight <- runif(ecount(g))
as_adjacency_matrix(g, attr="weight")
```

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

### Community examples

Looks like there are no examples yet.