create_adjacency: Create an adjacency matrix, or convert one to an edgelist

Description Usage Arguments Details Value Examples

View source: R/create_adjacency.R

Description

Creates a symmetric adjacency matrix from a simple data frame or edgelist from a matrix object that notes the connections.

Usage

1
2
3
create_adjacency(data, n1, n2, value = NULL, diagonal = NULL)

create_edges(adjmat, zeroEdges = FALSE, symmetric = FALSE, diag = FALSE)

Arguments

data

A data frame containing the nodes.

n1

column representing the first set of nodes.

n2

column representing the second set of nodes.

value

column representing the weight (otherwise will be set to 1).

diagonal

numeric value desired for the diagonal (defaults to a value of 1).

adjmat

A matrix like that produced with create_adjacency

zeroEdges

Include all possible edges or only those with values > 0?

symmetric

Include both A -> B and B -> A? FALSE assumes an undirected graph.

diag

Include diagonal (i.e. self connections)?

Details

The idea is to have this functionality without requiring any special graph or network object, as typical graphs can be represented rather simply using a data frame. n1 and n2 specify columns where the nodes in n1 are connected to nodes in n2. Value is an optional column name that will specify the weight of the connection See get.adjacency in igraph for an alternative.

create_edges assumes an adjacency matrix like that produced by create_adjacency

Value

A symmetric adjacency matrix with rows and columns pertaining to the unique values found in n1 and n2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(lazerhawk); library(dplyr)
nodeData = data.frame(pair=1:10,
node1 = sample(letters[1:4], 10, replace=TRUE),
                      node2 = sample(LETTERS[1:4], 10, replace=TRUE),
                      weight = runif(10),
                      diagonal = 0)
adjmat = create_adjacency(nodeData, n1='node1', n2='node2')
adjmat
adjmat = create_adjacency(nodeData, n1='node1', n2='node2', value='weight', diagonal=0)
adjmat

create_edges(adjmat)
create_edges(adjmat, symmetric=TRUE)

mclark--/lazerhawk documentation built on Sept. 8, 2020, 7:21 p.m.