edgeWeights {graph} | R Documentation |
Obtains the weights for all edges from the nodes specified by
index
.
edgeWeights(object, index)
object |
A graph, any object that inherits from the graph
class. |
index |
If supplied a character or numeric vector of node names or indices. |
If index
is suppled then edge weights from these nodes to all
adjacent nodes are found and returned. If index
is not supplied
then the edge weights for all nodes are returned.
The edgeData
method is the standard way to access edge
attribute information for a graph
instance. edgeWeights
provides a convenience wrapper around edgeData
. If an edge
attribute with name "weight"
is present, it will be used.
If the attribute values associated with "weight"
are not
vectors, an error will be triggered. Although any R object can be
specified as the attribute of an edge, the structure of the return
list of edgeWeights
only works with vector objects.
If no edge attribute with name "weight"
has been explicitly
defined, a default edge weight of 1 will be temporarily assigned; a
graph with no edge attributes defined will have edge weights of 1
according to edgeWeights
.
A named list of named edge weight vectors. The names on the list the
names of the nodes specified by index
, or all nodes if
index
was not provided. The names on the weight vectors are
node names to identify the edge to which the weight belongs.
R. Gentleman
V <- LETTERS[1:4] edL2 <- vector("list", length=4) names(edL2) <- V for(i in 1:4) edL2[[i]] <- list(edges=c(2,1,2,1)[i], weights=sqrt(i)) gR2 <- new("graphNEL", nodes=V, edgeL=edL2, edgemode="directed") edgeWeights(gR2, "C") edgeWeights(gR2) edgeData(gR2, attr="weight") edgeData(gR2, from="C", attr="weight")