Vertex and edge sequences

Vertex and edge sequences are the central concept of igraph.

igraph.vs.vector(graph, iterator)
igraph.vs.adj(graph, vid, mode="all")

igraph.vs.end(graph, iterator) igraph.vs.get(graph, iterator), iterator) igraph.vs.reset(graph, iterator)

vs$end vs$step vs$v, iterator), vid, mode="all"), iterator), iterator), iterator), iterator), iterator), iterator)

es$end es$e es$from es$to


A graph object.
A vertex or edge sequence.
Id of the vertex of which the adjacent vertices or edges will be selected.
Defines the type of adjacent vertices/edges to select. out is for outgoing edges, in for incoming ones, while all is both both of them.
A vertex sequence.
An edge sequence.
Not a real parameter, vs$end is TRUE if the vs sequence has no more vertices/edges to visit. See example below.
Not a real parameter, vs$step is a shorthand for,vs) and,es).
Shorthand for igraph.vs.get.
Shorthand for
es$from(graph) is a shorthand for, es).
es$to(graph) is a shorthand for, es).

igraph.vs.all creates a vertex sequence with all vertices of a graph.

igraph.vs.vector creates a vertex sequence from a vector of vertex ids.

igraph.vs.adj creates a vertex sequence containing the adjacent vertices of a vertex.

igraph.vs.end, igraph.vs.step, igraph.vs.get provide an iterator abstraction of a vertex set. igraph.vs.end checks whether there is another vertex to step to with the iterator. igraph.vs.get returns the vertex id at the current position of the iterator. igraph.vs.step moves to the next position.

igraph.vs.reset resets the iterator, this is equivalent to creating a new iterator of the same type, with the same parameters.

vs$end, vs$step, vs$v provide a simpler iterator-like interface. See the examples section below.

as.vector can be used on a vertex and edge sequence to coerce it to a regular numeric vector. creates an edge sequence containing all edges in the graph, their order will be arbitrary. creates an edge sequence with all edges. It is somewhat less efficient than, but the order of the edges is defined by the starting vertex of the edge. creates an edge set from a vector containing edge ids. creates an edge set containing the adjacent edges of a vertex. returns the id of the edge at the current iterator position. returns the starting vertex of the current edge. returns the end vertex of the current edge. checks whether there are more edges in the edge set to step to. steps to the next edge in the edge sequence. resets the iterator, it is equivalent to but slightly more efficient than creating a new edge sequence of the same type with the same parameters.

es$end, es$e, es$from(graph) and es$to(graph) provide a simpler iterator interface to edge sequences, see the examples below.

Note that, igraph.vs.reset, and don't change the iterator supplied as a parameter, but return the new, modified iterator.


  • igraph.vs.all, igraph.vs.vector, igraph.vs.adj return a vertex sequence.

    igraph.vs.end and return a logical constant.

    igraph.vs.get,,, and return a numeric constant. and igraph.vs.reset return the new vertex sequence. and return the new vertex sequence.

    as.vector returns a numeric vector.


## S3 method for class 'igraphvsseq': "$"(it, cmd) ## S3 method for class 'igraphvsvector': "$"(it, cmd) ## S3 method for class 'igraphesseq': "$"(it, cmd) ## S3 method for class 'igraphesvector': "$"(it, cmd) ## S3 method for class 'igraphvsseq': as.vector(x, mode="any") ## S3 method for class 'igraphvsvector': as.vector(x, mode="any") ## S3 method for class 'igraphesseq': as.vector(x, mode="any") ## S3 method for class 'igraphesvector': as.vector(x, mode="any")

  • $.igraphesseq
  • $.igraphesvector
  • igraph.vs.adj
  • igraph.vs.all
  • igraph.vs.end
  • igraph.vs.get
  • igraph.vs.reset
  • $.igraphvsseq
  • $.igraphvsvector
  • igraph.vs.vector
  • as.vector.igraphvsseq
  • as.vector.igraphvsvector
  • as.vector.igraphesseq
  • as.vector.igraphesvector
  • as.vector
# mean degree of vertices in the largest cluster in a random graph
g <-, 2/100)
c <- clusters(g)
vsl <- igraph.vs.vector(g, which(which.max(c$csize)-1==c$membership)-1)
mean(degree(g, vsl))

# set the color of these vertices to red, others greens
g <- add.vertex.attribute(g, "color", type="string")
v.a(g, "color") <- "green"
v.a(g, "color", vsl) <- "red"
plot(g, vertex.size=3, labels=NA, vertex.color="a:color")

# the longest geodesic within the largest cluster
vsl <- igraph.vs.reset(g, vsl) # just to be sure
long <- numeric()
while (!vsl$end) {
  paths <- get.shortest.paths(g, vsl$v)
  paths <- paths[ as.vector(vsl)+1  ]
  fl <- paths[[ which.max(sapply(paths, length)) ]]
  if (length(fl) > length(long)) {
    long <- fl
  vsl <- vsl$step
Documentation reproduced from package igraph, version 0.1.2, License: GPL version 2 or later (June, 1991)

Community examples

Looks like there are no examples yet.