Last data update: 2014.03.03

R: Retrieve the node weights of a graph
nodeWeightsR Documentation

Retrieve the node weights of a graph

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

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


library(graph)
V <- LETTERS[1:4]
g <- graphNEL(nodes = V, edgemode = "directed")
nodeWeights(g)
nodeWeights(g, "B")
nodeWeights(g, attr = "WT", default = 3)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ROntoTools)
Loading required package: graph
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: boot
Loading required package: KEGGREST
Loading required package: KEGGgraph

Attaching package: 'KEGGgraph'

The following object is masked from 'package:graphics':

    plot

Loading required package: Rgraphviz
Loading required package: grid
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/ROntoTools/nodeWeights.Rd_%03d_medium.png", width=480, height=480)
> ### Name: nodeWeights
> ### Title: Retrieve the node weights of a graph
> ### Aliases: nodeWeights nodeWeights,graph,character-method
> ###   nodeWeights,graph,missing-method nodeWeights,graph,numeric-method
> 
> ### ** Examples
> 
> 
> library(graph)
> V <- LETTERS[1:4]
> g <- graphNEL(nodes = V, edgemode = "directed")
> nodeWeights(g)
A B C D 
1 1 1 1 
> nodeWeights(g, "B")
B 
1 
> nodeWeights(g, attr = "WT", default = 3)
A B C D 
3 3 3 3 
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>