AdjacencyFromEdgelist: Convert an edgelist to an adjacency matrix

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

View source: R/AdjacencyFromEdgelist.R

Description

Given the adjacency matrix for a network return a data.frame listing all possible edges and the weights for each edge.

Usage

1
  AdjacencyFromEdgelist(elist, check.full = TRUE)

Arguments

elist

data.frame, see 'Details' for formatting assumptions.

check.full

logical, if TRUE ensures that all possible edges are in the list exactly once; if FALSE it assumes this is true.

Details

This assumes that elist is a data.frame with three columns. Each row is an edge in the network. The first column lists the node the edge is coming from, the second column lists the node the edge is going to, and the third column lists the weight of the edge.

Value

list, containing an adjacency matrix and a vector of node ids identifying the rows and columns.

adjacency The adjacency matrix for the network. The row indicates the node the edge is coming 'from', the column indicates the node the edge is going 'to', and the value in the adjacency matrix is the weight given to the edge.
nodelist The ids of the nodes in the same order as the the rows and columns of the adjacency matrix.

Author(s)

Stephen R. Haptonstahl srh@haptonstahl.org

References

https://github.com/shaptonstahl/

See Also

EdgelistFill

Examples

1
2
edgelist <- cbind(expand.grid(letters[1:2], letters[1:2]), runif(4))
AdjacencyFromEdgelist(edgelist)

Example output

Loading required package: igraph

Attaching package: 'igraph'

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

    decompose, spectrum

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

    union

Loading required package: Rcpp
$adjacency
          [,1]      [,2]
[1,] 0.6637028 0.9408983
[2,] 0.2853941 0.6346857

$nodelist
[1] a b
Levels: a b

dils documentation built on May 2, 2019, 8:28 a.m.