I have an adjacency matrix with 4 columns. The first 2 columns are the source and target nodes that I want to become vertices in my igraph object. I can achieve this with the code below.
al <- data.frame(sourceNode=c('a', 'a', 'b', 'c'),
consumerNode=c('b', 'c', 'c', 'a'),
edgeAtt1=c('highway', 'road', 'road', 'path'),
edgeAtt2=c('1999', '2010', '2014', '1999'))
require('igraph')
g <- graph.edgelist(as.matrix(al[,c('sourceNode', 'consumerNode')]))
However, what I want to do is include columns 3 and 4 from al
as edge attributes when I create this igraph object.
Some function functionThatINeed
that lets me do something like this:
g <- functionThatINeed(al[,c('sourceNode', 'consumerNode')]), edgeAttributes=al[,c('edgeAtt1', 'edgeAtt2')])