nodeWeights: Retrieve the node weights of a graph

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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.

Usage

 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)

Arguments

object

A graph, any object that inherits the graph class.

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 object has no node attribute named by the value of attr. The default is the value 1.

Details

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.

Value

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.

Author(s)

Calin Voichita and Sorin Draghici

See Also

nodes, nodeData

Examples

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)

ROntoTools documentation built on Nov. 8, 2020, 7:41 p.m.