EVOLUTION-MANAGER
Edit File: sub-.igraph.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: Query and manipulate a graph as it were 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 [.igraph {igraph}"><tr><td>[.igraph {igraph}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Query and manipulate a graph as it were an adjacency matrix</h2> <h3>Description</h3> <p>Query and manipulate a graph as it were an adjacency matrix </p> <h3>Usage</h3> <pre> ## S3 method for class 'igraph' x[ i, j, ..., from, to, sparse = igraph_opt("sparsematrices"), edges = FALSE, drop = TRUE, attr = if (is_weighted(x)) "weight" else NULL ] </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>The graph.</p> </td></tr> <tr valign="top"><td><code>i</code></td> <td> <p>Index. Vertex ids or names or logical vectors. See details below.</p> </td></tr> <tr valign="top"><td><code>j</code></td> <td> <p>Index. Vertex ids or names or logical vectors. See details below.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Currently ignored.</p> </td></tr> <tr valign="top"><td><code>from</code></td> <td> <p>A numeric or character vector giving vertex ids or names. Together with the <code>to</code> argument, it can be used to query/set a sequence of edges. See details below. This argument cannot be present together with any of the <code>i</code> and <code>j</code> arguments and if it is present, then the <code>to</code> argument must be present as well.</p> </td></tr> <tr valign="top"><td><code>to</code></td> <td> <p>A numeric or character vector giving vertex ids or names. Together with the <code>from</code> argument, it can be used to query/set a sequence of edges. See details below. This argument cannot be present together with any of the <code>i</code> and <code>j</code> arguments and if it is present, then the <code>from</code> argument must be present as well.</p> </td></tr> <tr valign="top"><td><code>sparse</code></td> <td> <p>Logical scalar, whether to return sparse matrices.</p> </td></tr> <tr valign="top"><td><code>edges</code></td> <td> <p>Logical scalar, whether to return edge ids.</p> </td></tr> <tr valign="top"><td><code>drop</code></td> <td> <p>Ignored.</p> </td></tr> <tr valign="top"><td><code>attr</code></td> <td> <p>If not <code>NULL</code>, then it should be the name of an edge attribute. This attribute is queried and returned.</p> </td></tr> </table> <h3>Details</h3> <p>The single bracket indexes the (possibly weighted) adjacency matrix of the graph. Here is what you can do with it: </p> <ol> <li><p> Check whether there is an edge between two vertices (<i>v</i> and <i>w</i>) in the graph: </p> <pre> graph[v, w]</pre> <p>A numeric scalar is returned, one if the edge exists, zero otherwise. </p> </li> <li><p> Extract the (sparse) adjacency matrix of the graph, or part of it: </p> <pre> graph[] graph[1:3,5:6] graph[c(1,3,5),]</pre> <p>The first variants returns the full adjacency matrix, the other two return part of it. </p> </li> <li><p> The <code>from</code> and <code>to</code> arguments can be used to check the existence of many edges. In this case, both <code>from</code> and <code>to</code> must be present and they must have the same length. They must contain vertex ids or names. A numeric vector is returned, of the same length as <code>from</code> and <code>to</code>, it contains ones for existing edges edges and zeros for non-existing ones. Example: </p> <pre> graph[from=1:3, to=c(2,3,5)]</pre><p>. </p> </li> <li><p> For weighted graphs, the <code>[</code> operator returns the edge weights. For non-esistent edges zero weights are returned. Other edge attributes can be queried as well, by giving the <code>attr</code> argument. </p> </li> <li><p> Querying edge ids instead of the existance of edges or edge attributes. E.g. </p> <pre> graph[1, 2, edges=TRUE]</pre> <p>returns the id of the edge between vertices 1 and 2, or zero if there is no such edge. </p> </li> <li><p> Adding one or more edges to a graph. For this the element(s) of the imaginary adjacency matrix must be set to a non-zero numeric value (or <code>TRUE</code>): </p> <pre> graph[1, 2] <- 1 graph[1:3,1] <- 1 graph[from=1:3, to=c(2,3,5)] <- TRUE</pre> <p>This does not affect edges that are already present in the graph, i.e. no multiple edges are created. </p> </li> <li><p> Adding weighted edges to a graph. The <code>attr</code> argument contains the name of the edge attribute to set, so it does not have to be ‘weight’: </p> <pre> graph[1, 2, attr="weight"]<- 5 graph[from=1:3, to=c(2,3,5)] <- c(1,-1,4)</pre> <p>If an edge is already present in the network, then only its weights or other attribute are updated. If the graph is already weighted, then the <code>attr="weight"</code> setting is implicit, and one does not need to give it explicitly. </p> </li> <li><p> Deleting edges. The replacement syntax allow the deletion of edges, by specifying <code>FALSE</code> or <code>NULL</code> as the replacement value: </p> <pre> graph[v, w] <- FALSE</pre> <p>removes the edge from vertex <i>v</i> to vertex <i>w</i>. As this can be used to delete edges between two sets of vertices, either pairwise: </p> <pre> graph[from=v, to=w] <- FALSE</pre> <p>or not: </p> <pre> graph[v, w] <- FALSE </pre> <p>if <i>v</i> and <i>w</i> are vectors of edge ids or names. </p> </li></ol> <p>‘<code>[</code>’ allows logical indices and negative indices as well, with the usual R semantics. E.g. </p> <pre> graph[degree(graph)==0, 1] <- 1</pre> <p>adds an edge from every isolate vertex to vertex one, and </p> <pre> G <- make_empty_graph(10) G[-1,1] <- TRUE</pre> <p>creates a star graph. </p> <p>Of course, the indexing operators support vertex names, so instead of a numeric vertex id a vertex can also be given to ‘<code>[</code>’ and ‘<code>[[</code>’. </p> <h3>Value</h3> <p>A scalar or matrix. See details below. </p> <h3>See Also</h3> <p>Other structural queries: <code><a href="sub-sub-.igraph.html">[[.igraph</a>()</code>, <code><a href="adjacent_vertices.html">adjacent_vertices</a>()</code>, <code><a href="are_adjacent.html">are_adjacent</a>()</code>, <code><a href="ends.html">ends</a>()</code>, <code><a href="get.edge.ids.html">get.edge.ids</a>()</code>, <code><a href="gorder.html">gorder</a>()</code>, <code><a href="gsize.html">gsize</a>()</code>, <code><a href="head_of.html">head_of</a>()</code>, <code><a href="incident_edges.html">incident_edges</a>()</code>, <code><a href="incident.html">incident</a>()</code>, <code><a href="is_directed.html">is_directed</a>()</code>, <code><a href="neighbors.html">neighbors</a>()</code>, <code><a href="tail_of.html">tail_of</a>()</code> </p> <hr /><div style="text-align: center;">[Package <em>igraph</em> version 1.3.5 <a href="00Index.html">Index</a>]</div> </body></html>