How do I calculate weighted degree distributions with igraph in R?

Consider a dataframe df where the first two columns are node pairs and successive columns V1, V2, ..., Vn represent flows between the nodes (potentially 0, implying no edge for that column's network). I would like to conduct analysis on degree, community detection, and other network measures using the flows as weights.

Then to analyze the graph with respect to the weights in V1 I do:

# create graph and explore unweighted degrees with respect to V1
g <- df[df$V1!=0,] )
x <- 0:max(degree(g))

# set weights and explore weighted degrees using V1
E(g)$weights <- E(g)$V1

The output from the third qplot is no different than the first. What am I doing wrong?


So graph.strength is what I am looking for, but graph.strength(g) in my case gives standard degree output followed by:

Warning message:
In graph.strength(g) :
At structural_properties.c:4928 :No edge weights for strength calculation,
normal degree

I must be setting the weights incorrectly, is it not sufficient to do E(g)$weights <- E(g)$V1 and why can g$weights differ from E(g)$weights?


The function graph.strength can be given a weights vector with the weights argument. I think what is going wrong in your code is that you should call the weights attribute E(g)$weight not E(g)$weights.

Need Your Help

Turn on/off GPS programmatically without prompting the user in iphone

iphone objective-c ios

I'm planning to code an application for the times when someone's iphone is lost or stolen. So it needs to tell the location of the phone via GPS, but in case it's stolen, it wouldn't be a good idea...

MongoDB and Java driver: “ignore case” in query

java mongodb case-insensitive

This is the code I'm using now, how do I add the "ignore case" attribute?