Edge sequences can be indexed very much like a plain numeric R vector, with some extras.

## Multiple indices

When using multiple indices within the bracket, all of them
are evaluated independently, and then the results are concatenated
using the `c()`

function. E.g. `E(g)[1, 2, .inc(1)]`

is equivalent to `c(E(g)[1], E(g)[2], E(g)[.inc(1)])`

.

## Index types

Edge sequences can be indexed with positive numeric vectors, negative numeric vectors, logical vectors, character vectors:

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.

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.

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

`TRUE`

are selected.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

`|`

bar character to select an edges that incident to the two given vertices. See examples below.

## Edge attributes

When indexing edge sequences, edge attributes can be referred
to simply by using their names. E.g. if a graph has a `weight`

edge
attribute, then `E(G)[weight > 1]`

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 `.env`

pronoun to perform the name lookup in the calling
environment. In other words, use `E(g)[.env$weight > 1]`

to make sure
that `weight`

is looked up from the calling environment even if there is
an edge attribute with the same name. Similarly, you can use `.data`

to
match attribute names only.

## Special functions

There are some special igraph functions that can be used only in expressions indexing edge sequences:

`.inc`

takes a vertex sequence, and selects all edges that have at least one incident vertex in the vertex sequence.

`.from`

similar to

`.inc()`

, but only the tails of the edges are considered.`.to`

is similar to

`.inc()`

, but only the heads of the edges are considered.`\%--\%`

a special operator that can be used to select all edges between two sets of vertices. It ignores the edge directions in directed graphs.

`\%->\%`

similar to

`\%--\%`

, but edges*from*the left hand side argument, pointing*to*the right hand side argument, are selected, in directed graphs.`\%<-\%`

similar to

`\%--\%`

, but edges*to*the left hand side argument, pointing*from*the right hand side argument, are selected, in directed graphs.

Note that multiple special functions can be used together, or with regular indices, and then their results are concatenated. See more examples below.

## See also

Other vertex and edge sequences:
`E()`

,
`V()`

,
`as_ids()`

,
`igraph-es-attributes`

,
`igraph-es-indexing2`

,
`igraph-vs-attributes`

,
`igraph-vs-indexing2`

,
`igraph-vs-indexing`

,
`print.igraph.es()`

,
`print.igraph.vs()`

Other vertex and edge sequence operations:
`c.igraph.es()`

,
`c.igraph.vs()`

,
`difference.igraph.es()`

,
`difference.igraph.vs()`

,
`igraph-es-indexing2`

,
`igraph-vs-indexing2`

,
`igraph-vs-indexing`

,
`intersection.igraph.es()`

,
`intersection.igraph.vs()`

,
`rev.igraph.es()`

,
`rev.igraph.vs()`

,
`union.igraph.es()`

,
`union.igraph.vs()`

,
`unique.igraph.es()`

,
`unique.igraph.vs()`

## Examples

```
# -----------------------------------------------------------------
# Special operators for indexing based on graph structure
g <- sample_pa(100, power = 0.3)
E(g)[1:3 %--% 2:6]
#> + 5/99 edges from 08754d4:
#> [1] 2->1 3->2 4->1 5->1 6->1
E(g)[1:5 %->% 1:6]
#> + 4/99 edges from 08754d4:
#> [1] 2->1 3->2 4->1 5->1
E(g)[1:3 %<-% 2:6]
#> + 5/99 edges from 08754d4:
#> [1] 2->1 3->2 4->1 5->1 6->1
# -----------------------------------------------------------------
# The edges along the diameter
g <- sample_pa(100, directed = FALSE)
d <- get_diameter(g)
E(g, path = d)
#> + 11/99 edges from fc174e1:
#> [1] 20--46 16--20 11--16 9--11 1-- 9 1-- 3 3--17 17--45 45--63 63--81
#> [11] 81--82
# -----------------------------------------------------------------
# Select edges based on attributes
g <- sample_gnp(20, 3 / 20) %>%
set_edge_attr("weight", value = rnorm(gsize(.)))
E(g)[[weight < 0]]
#> + 16/32 edges from ee0e12e:
#> tail head tid hid weight
#> 2 3 6 3 6 -2.1691432
#> 4 3 7 3 7 -1.1377713
#> 7 7 9 7 9 -0.6199144
#> 9 8 10 8 10 -1.5413736
#> 11 7 11 7 11 -0.5745179
#> 14 9 14 9 14 -1.2127357
#> 16 2 16 2 16 -1.1184588
#> 17 4 16 4 16 -0.4535614
#> 19 4 17 4 17 -1.3225454
#> 21 15 17 15 17 -0.1472086
#> 22 1 18 1 18 -1.5822800
#> 23 5 18 5 18 -0.5166923
#> 24 12 18 12 18 -1.7821347
#> 25 14 18 14 18 -1.0942744
#> 26 6 19 6 19 -0.6835354
#> 30 6 20 6 20 -1.0439761
# 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]
#> + 1/32 edge from ee0e12e:
#> [1] 3--6
```