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?
In weighted graphs, a real number is assigned to each (directed or undirected) edge. The input graph. In igraph edge weights are represented via an edge attribute, called ‘weight’.
In igraph edge weights are represented via an edge attribute, called ‘weight’. The is_weighted function only checks that such an attribute exists. (It does not even checks that it is a numeric edge attribute.) Edge weights are used for different purposes by the different functions.
You can add edges by calling Graph.add_edges () - but in order to add edges, you have to refer to existing vertices somehow. igraph uses integer vertex IDs starting from zero, thus the first vertex of your graph has index zero, the second vertex has index 1 and so on.
Your best bet is probably GraphML or GML if you want to save igraph graphs in a format that can be read from an external package and you want to preserve numeric and string attributes. Edge list and NCOL is also fine if you don’t have attributes (NCOL supports vertex names and edge weights, though).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With