EVOLUTION-MANAGER
Edit File: igraph-es-indexing.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: Indexing edge sequences</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-es-indexing {igraph}"><tr><td>igraph-es-indexing {igraph}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Indexing edge sequences</h2> <h3>Description</h3> <p>Edge sequences can be indexed very much like a plain numeric R vector, with some extras. </p> <h3>Usage</h3> <pre> ## S3 method for class 'igraph.es' x[...] </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>An edge sequence</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Indices, see details below.</p> </td></tr> </table> <h3>Value</h3> <p>Another edge sequence, referring to the same graph. </p> <h3>Multiple indices</h3> <p>When using multiple indices within the bracket, all of them are evaluated independently, and then the results are concatenated using the <code>c()</code> function. E.g. <code>E(g)[1, 2, .inc(1)]</code> is equivalent to <code>c(E(g)[1], E(g)[2], E(g)[.inc(1)])</code>. </p> <h3>Index types</h3> <p>Edge sequences can be indexed with positive numeric vectors, negative numeric vectors, logical vectors, character vectors: </p> <ul> <li><p> When indexed with positive numeric vectors, the edges at the given positions in the sequence are selected. This is the same as indexing a regular R atomic vector with positive numeric vectors. </p> </li> <li><p> When indexed with negative numeric vectors, the edges at the given positions in the sequence are omitted. Again, this is the same as indexing a regular R atomic vector. </p> </li> <li><p> When indexed with a logical vector, the lengths of the edge sequence and the index must match, and the edges for which the index is <code>TRUE</code> are selected. </p> </li> <li><p> Named graphs can be indexed with character vectors, to select edges with the given names. Note that a graph may have edge names and vertex names, and both can be used to select edges. Edge names are simply used as names of the numeric edge id vector. Vertex names effectively only work in graphs without multiple edges, and must be separated with a <code>|</code> bar character to select an edges that incident to the two given vertices. See examples below. </p> </li></ul> <h3>Edge attributes</h3> <p>When indexing edge sequences, edge attributes can be referred to simply by using their names. E.g. if a graph has a <code>weight</code> edge attribute, then <code>E(G)[weight > 1]</code> selects all edges with a weight larger than one. See more examples below. Note that attribute names mask the names of variables present in the calling environment; if you need to look up a variable and you do not want a similarly named edge attribute to mask it, use the <code>.env</code> pronoun to perform the name lookup in the calling environment. In other words, use <code>E(g)[.env$weight > 1]</code> to make sure that <code>weight</code> is looked up from the calling environment even if there is an edge attribute with the same name. Similarly, you can use <code>.data</code> to match attribute names only. </p> <h3>Special functions</h3> <p>There are some special igraph functions that can be used only in expressions indexing edge sequences: </p> <dl> <dt><code>.inc</code></dt><dd><p>takes a vertex sequence, and selects all edges that have at least one incident vertex in the vertex sequence.</p> </dd> <dt><code>.from</code></dt><dd><p>similar to <code>.inc()</code>, but only the tails of the edges are considered.</p> </dd> <dt><code>.to</code></dt><dd><p>is similar to <code>.inc()</code>, but only the heads of the edges are considered.</p> </dd> <dt><code>%--%</code></dt><dd><p>a special operator that can be used to select all edges between two sets of vertices. It ignores the edge directions in directed graphs.</p> </dd> <dt><code>%->%</code></dt><dd><p>similar to <code>%--%</code>, but edges <em>from</em> the left hand side argument, pointing <em>to</em> the right hand side argument, are selected, in directed graphs.</p> </dd> <dt><code>%<-%</code></dt><dd><p>similar to <code>%--%</code>, but edges <em>to</em> the left hand side argument, pointing <em>from</em> the right hand side argument, are selected, in directed graphs.</p> </dd> </dl> <p>Note that multiple special functions can be used together, or with regular indices, and then their results are concatenated. See more examples below. </p> <h3>See Also</h3> <p>Other vertex and edge sequences: <code><a href="E.html">E</a>()</code>, <code><a href="V.html">V</a>()</code>, <code><a href="igraph-es-attributes.html">igraph-es-attributes</a></code>, <code><a href="igraph-es-indexing2.html">igraph-es-indexing2</a></code>, <code><a href="igraph-vs-attributes.html">igraph-vs-attributes</a></code>, <code><a href="igraph-vs-indexing2.html">igraph-vs-indexing2</a></code>, <code><a href="igraph-vs-indexing.html">igraph-vs-indexing</a></code>, <code><a href="print.igraph.es.html">print.igraph.es</a>()</code>, <code><a href="print.igraph.vs.html">print.igraph.vs</a>()</code> </p> <p>Other vertex and edge sequence operations: <code><a href="c.igraph.es.html">c.igraph.es</a>()</code>, <code><a href="c.igraph.vs.html">c.igraph.vs</a>()</code>, <code><a href="difference.igraph.es.html">difference.igraph.es</a>()</code>, <code><a href="difference.igraph.vs.html">difference.igraph.vs</a>()</code>, <code><a href="igraph-es-indexing2.html">igraph-es-indexing2</a></code>, <code><a href="igraph-vs-indexing2.html">igraph-vs-indexing2</a></code>, <code><a href="igraph-vs-indexing.html">igraph-vs-indexing</a></code>, <code><a href="intersection.igraph.es.html">intersection.igraph.es</a>()</code>, <code><a href="intersection.igraph.vs.html">intersection.igraph.vs</a>()</code>, <code><a href="rev.igraph.es.html">rev.igraph.es</a>()</code>, <code><a href="rev.igraph.vs.html">rev.igraph.vs</a>()</code>, <code><a href="union.igraph.es.html">union.igraph.es</a>()</code>, <code><a href="union.igraph.vs.html">union.igraph.vs</a>()</code>, <code><a href="unique.igraph.es.html">unique.igraph.es</a>()</code>, <code><a href="unique.igraph.vs.html">unique.igraph.vs</a>()</code> </p> <h3>Examples</h3> <pre> # ----------------------------------------------------------------- # Special operators for indexing based on graph structure g <- sample_pa(100, power = 0.3) E(g) [ 1:3 %--% 2:6 ] E(g) [ 1:5 %->% 1:6 ] E(g) [ 1:3 %<-% 2:6 ] # ----------------------------------------------------------------- # The edges along the diameter g <- sample_pa(100, directed = FALSE) d <- get_diameter(g) E(g, path = d) # ----------------------------------------------------------------- # Select edges based on attributes g <- sample_gnp(20, 3/20) %>% set_edge_attr("weight", value = rnorm(gsize(.))) E(g)[[ weight < 0 ]] # Indexing with a variable whose name matches the name of an attribute # may fail; use .env to force the name lookup in the parent environment E(g)$x <- E(g)$weight x <- 2 E(g)[.env$x] </pre> <hr /><div style="text-align: center;">[Package <em>igraph</em> version 1.3.5 <a href="00Index.html">Index</a>]</div> </body></html>