Import weighted edgelist using igraph

user1723765 picture user1723765 · Oct 13, 2012 · Viewed 8.7k times · Source

I have the following txt file representing a network in edgelist format.

The first two columns represent the usual: which node is connected to which other nodes

The third column represents weights, representing the number of times each node has contacted the other.

I have searched the igraph documentation but there's no mention of how to include an argument for weight when importing standard file formats like txt.

The file can be accessed from here and this is the code I've been using:

read.graph("Irvine/OClinks_w.txt", format="edgelist")

This code treats the third column as something other than weight.

Does anyone know the solution?

Answer

user1317221_G picture user1317221_G · Oct 13, 2012

does the following cause too much annoyance?

g <- read.table("Irvine/OClinks_w.txt")
g <- graph.data.frame(g)

if it does then directly from the file you can use

g<-read.graph("Irvine/OClinks_w.txt",format="ncol")
E(g)$weight