Indexing for edge extraction operates in a manner analogous to matrix
objects. Thus, x[,]
selects all vertex pairs, x[1,-5]
selects
the pairing of vertex 1 with all vertices except for 5, etc. Following
this, it is acceptable for i
and/or j
to be logical vectors
indicating which vertices are to be included. During assignment, an attempt
is made to match the elements of value
to the extracted pairs in an
intelligent way; in particular, elements of value
will be replicated
if too few are supplied (allowing expressions like x[1,]<-1
). Where
names.eval==NULL
, zero and non-zero values are taken to indicate the
presence of absence of edges. x[2,4]<-6
thus adds a single (2,4)
edge to x
, and x[2,4]<-0
removes such an edge (if present).
If x
is multiplex, assigning 0 to a vertex pair will eliminate
all edges on that pair. Pairs are taken to be directed where
is.directed(x)==TRUE
, and undirected where
is.directed(x)==FALSE
.
If an edge attribute is specified using names.eval
, then the provided
values will be assigned to that attribute. When assigning values, only
extant edges are employed (unless add.edges==TRUE
); in the latter
case, any non-zero assignment results in the addition of an edge where
currently absent. If the attribute specified is not present on a given
edge, it is added. Otherwise, any existing value is overwritten. The
%e%
operator can also be used to extract/assign edge values; in those
roles, it is respectively equivalent to get.edge.value(x,attrname)
and set.edge.value(x,attrname=attrname,value=value)
(if value
is a matrix) and set.edge.attribute(x,attrname=attrname,value=value)
(if value
is anything else). That is, if value
is a matrix,
the assignment operator treats it as an adjacency matrix; and if not, it
treats it as a vector (recycled as needed) in the internal ordering of edges
(i.e., edge IDs), skipping over deleted edges. In no case will attributes be
assigned to nonexisted edges.
The %n%
and %v%
operators serve as front-ends to the network
and vertex extraction/assignment functions (respectively). In the
extraction case, x %n% attrname
is equivalent to
get.network.attribute(x,attrname)
, with x %v% attrname
corresponding to get.vertex.attribute(x,attrname)
. In assignment,
the respective equivalences are to
set.network.attribute(x,attrname,value)
and
set.vertex.attribute(x,attrname,value)
. Note that the %%
assignment forms are generally slower than the named versions of the
functions beause they will trigger an additional internal copy of the
network object.
The %eattr%
, %nattr%
, and %vattr%
operators are
equivalent to %e%
, %n%
, and %v%
(respectively). The
short forms are more succinct, but may produce less readable code.