EVOLUTION-MANAGER
Edit File: as_adjacency_matrix.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Convert a graph to an adjacency matrix</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for as_adjacency_matrix {igraph}"><tr><td>as_adjacency_matrix {igraph}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Convert a graph to an adjacency matrix</h2> <h3>Description</h3> <p>Sometimes it is useful to work with a standard representation of a graph, like an adjacency matrix. </p> <h3>Usage</h3> <pre> 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") ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>graph</code></td> <td> <p>The graph to convert.</p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>Gives how to create the adjacency matrix for undirected graphs. It is ignored for directed graphs. Possible values: <code>upper</code>: the upper right triangle of the matrix is used, <code>lower</code>: the lower left triangle of the matrix is used. <code>both</code>: the whole matrix is used, a symmetric matrix is returned.</p> </td></tr> <tr valign="top"><td><code>attr</code></td> <td> <p>Either <code>NULL</code> or a character string giving an edge attribute name. If <code>NULL</code> a traditional adjacency matrix is returned. If not <code>NULL</code> then the values of the given edge attribute are included in the adjacency matrix. If the graph has multiple edges, the edge attribute of an arbitrarily chosen edge (for the multiple edges) is included. This argument is ignored if <code>edges</code> is <code>TRUE</code>. </p> <p>Note that this works only for certain attribute types. If the <code>sparse</code> argumen is <code>TRUE</code>, then the attribute must be either logical or numeric. If the <code>sparse</code> argument is <code>FALSE</code>, then character is also allowed. The reason for the difference is that the <code>Matrix</code> package does not support character sparse matrices yet.</p> </td></tr> <tr valign="top"><td><code>edges</code></td> <td> <p>Logical scalar, whether to return the edge ids in the matrix. For non-existant edges zero is returned.</p> </td></tr> <tr valign="top"><td><code>names</code></td> <td> <p>Logical constant, whether to assign row and column names to the matrix. These are only assigned if the <code>name</code> vertex attribute is present in the graph.</p> </td></tr> <tr valign="top"><td><code>sparse</code></td> <td> <p>Logical scalar, whether to create a sparse matrix. The ‘<code>Matrix</code>’ package must be installed for creating sparse matrices.</p> </td></tr> </table> <h3>Details</h3> <p><code>as_adjacency_matrix</code> returns the adjacency matrix of a graph, a regular matrix if <code>sparse</code> is <code>FALSE</code>, or a sparse matrix, as defined in the ‘<code>Matrix</code>’ package, if <code>sparse</code> if <code>TRUE</code>. </p> <h3>Value</h3> <p>A <code>vcount(graph)</code> by <code>vcount(graph)</code> (usually) numeric matrix. </p> <h3>See Also</h3> <p><code><a href="graph_from_adjacency_matrix.html">graph_from_adjacency_matrix</a></code>, <code><a href="read_graph.html">read_graph</a></code> </p> <h3>Examples</h3> <pre> 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") </pre> <hr /><div style="text-align: center;">[Package <em>igraph</em> version 1.3.5 <a href="00Index.html">Index</a>]</div> </body></html>