igraph-es-indexing: Indexing edge sequences

Description Usage Arguments Value Multiple indices Index types Edge attributes Special functions See Also Examples

Description

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

Usage

1
2
## S3 method for class 'igraph.es'
x[...]

Arguments

x

An edge sequence

...

Indices, see details below.

Value

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:

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.

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(), 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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 ]]

igraph documentation built on March 19, 2020, 5:13 p.m.