newgraph: Create a graph object of class graph

Description Usage Arguments Value Author(s) See Also Examples

View source: R/graphtools.R

Description

Create a graph object of class graphNEL or graphAM. You might also use the graph creating facility provided by the graph package.

Usage

1
newgraph(nodeNames, mat, weights = NULL, directed = FALSE, isAdjacency = FALSE, ...)

Arguments

nodeNames

Numeric or character string vector.

mat

Either an adjacency matrix or a from to matrix.

weights

Numeric weights for edges. Either in the same order as the from to matrix or as a square matrix, depending what one have chosen for the mat argument.

directed

Logical value for defining a directed or undirected graph.

isAdjacency

If argument mat is adjacency matrix.

...

Currently not needed.

Value

graphNEL or grapAM object.

Author(s)

Adrian Waddell and R. Wayne Oldford

See Also

navGraph, completegraph, linegraph

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Using from to matrices
from <- c("A","A","C","C")
to   <- c("B","C","B","D")
ftEmat <- cbind(from,to)

## note how the E node is added
G <- newgraph(nodeNames = LETTERS[1:5], mat = ftEmat)

## say you would like to add weights to the graph
weights <- c(2,1,3,4)
G <- newgraph(nodeNames = LETTERS[1:5], mat = ftEmat, weights = weights)

## newgraph with adjacency matrix
V <- c('s.L', 's.W', 'p.L', 'p.W')
adjM <- matrix(c(0,1,1,0,1,0,1,1,1,1,0,0,0,1,0,0), ncol = 4)
all(adjM == t(adjM)) ## is symmetric (undirected)
G <- newgraph(nodeNames = V, mat= adjM, isAdjacency=TRUE)

## if you use adjacency matrices, you can add a matrix with weights
adjM <-     matrix(c(0,0,1,0,1,0,1,1,0,0,0,0,0,1,0,0), ncol = 4)
weightsM <- matrix(c(0,0,5,0,2,0,1,3,0,0,0,0,0,7,0,0), ncol = 4)
G <- newgraph(nodeNames = V, mat= adjM, weights = weightsM, directed = TRUE, isAdjacency=TRUE)
edgeData(G, attr = "weight")


RnavGraph documentation built on May 19, 2017, 2 p.m.
Search within the RnavGraph package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.