edge2Mat: Convert network edges to adjacency matrix

View source: R/edge2Mat.R

edge2MatR Documentation

Convert network edges to adjacency matrix

Description

Convert network edges to adjacency matrix

Usage

edge2Mat(edge, rownm, colnm, direction = TRUE, rmName = FALSE, restValue = 0)

Arguments

edge

a data.frame of three columns, the first two columns represent nodes in a network, the third column is the weight.

rownm

row names in the final adjacency matrix. All node names must present in either rownm or colnm.

colnm

column names in the final adjacency matrix. All node names must present in either rownm or colnm.

direction

logic, whether this network is directed, the default is TRUE.

rmName

logic, whether to remove row names and column names in the adjacency matrix.

restValue

the value to fill in the blank edges.

Value

An adjacency matrix.

Examples

## Not run: 
edge = data.frame(c("a", "b", "c"), c("a", "c", "d"), c(1,1,1))
edge2Mat(edge, edge[,1], edge[,2])

nodes = unique(c(as.character(edge[,1]), as.character(edge[,2])))
edge2Mat(edge, nodes, nodes)

edge2Mat(edge, nodes, nodes,direction = FALSE)
edge2Mat(edge, nodes, nodes,direction = FALSE, rmName = TRUE)

edge = data.frame(c(1:3), c(3:5), c(1,1,1))
edge2Mat(edge,  edge[,1],  edge[,2] )

## End(Not run)

paodan/funcTools documentation built on April 1, 2024, 12:01 a.m.