Indexing edge sequences

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

## S3 method for class 'igraph.es':
[(x, ...)
An edge sequence
Indices, see details below.

  • Another edge sequence, referring to the same graph.

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 isTRUEare 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 nuumeric 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 refered 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 larger than one weight. See more examples below.

See Also

Other vertex and edge sequence operations: [.igraph.vs, igraph-vs-indexing; [[.igraph.es, igraph-es-indexing2; [[.igraph.vs, igraph-vs-indexing2; c.igraph.es; c.igraph.vs; difference.igraph.es; difference.igraph.vs; intersection.igraph.es; intersection.igraph.vs; rev.igraph.es; rev.igraph.vs; union.igraph.es; union.igraph.vs; unique.igraph.es; unique.igraph.vs

Other vertex and edge sequences: $.igraph.es, $<-.igraph.es, E<-, [<-.igraph.es, [[<-.igraph.es, igraph-es-attributes, igraph-es-attributes, igraph-es-attributes, igraph-es-attributes, igraph-es-attributes; $.igraph.vs, $<-.igraph.vs, V<-, [<-.igraph.vs, [[<-.igraph.vs, igraph-vs-attributes, igraph-vs-attributes, igraph-vs-attributes, igraph-vs-attributes, igraph-vs-attributes; E; V; [.igraph.vs, igraph-vs-indexing; [[.igraph.es, igraph-es-indexing2; [[.igraph.vs, igraph-vs-indexing2; print.igraph.es; print.igraph.vs

  • [.igraph.es
  • %--%
  • %->%
  • %<-%
  • igraph-es-indexing
# 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 ]]
Documentation reproduced from package igraph, version 1.0.0, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.