Description Usage Arguments Details Value Author(s) See Also Examples
A generic function that returns the node weights of a graph. If index
is specified, only the weights of the specified nodes are returned. The user can control which node attribute is interpreted as the weight.
1 2 3 4 5 6 7 8 9 10 | nodeWeights(object, index, ..., attr = "weight", default = 1)
## S4 method for signature 'graph,character'
nodeWeights(object, index, attr, default)
## S4 method for signature 'graph,numeric'
nodeWeights(object, index, attr, default)
## S4 method for signature 'graph,missing'
nodeWeights(object, index, attr, default)
|
object |
A graph, any object that inherits the |
index |
If supplied, a character or numeric vector of node names or indices. |
... |
Unused. |
attr |
The name of the node attribute to use as a weight. You can view the list of defined node attributes and their default values using nodeDataDefaults. |
default |
The value to use if |
The weights of all nodes identified by the index
are returned. If index
is not supplied, the weights of all nodes are returned.
By default, nodeWeights
looks for an node attribute with name "weight" and, if found, uses these values to construct the node weight vector.
You can make use of attributes stored under a different name by providing a value for the attr
argument.
For example, if object
is a graph instance with an node attribute named "WTS", then the call nodeWeights(object, attr="WTS")
will attempt to use those values.
If the graph instance does not have an node attribute with name given by the value of the attr
argument, default
will be used as the weight for all nodes.
Note that if there is an attribute named by attr
, then its default value will be used for nodes not specifically customized.
See nodeData and nodeDataDefaults for more information.
A named vector with the node weights. The names of the vector are the names of the specified index
, or all nodes if index
was not provided.
Calin Voichita and Sorin Draghici
nodes, nodeData
1 2 3 4 5 6 | library(graph)
V <- LETTERS[1:4]
g <- graphNEL(nodes = V, edgemode = "directed")
nodeWeights(g)
nodeWeights(g, "B")
nodeWeights(g, attr = "WT", default = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.