I have a large igraph object with almost a 1M nodes and 1.5M edges. After researching a while I could not find a procedure to sum a node's neighbors attributes, in this case, it's a binary one. At the moment, the best solution I found way the following:
V(g)$sum = sapply( ego(g,1,V(g),mode = 'all',mindist = 1), function(v) sum(V(G)[v]$attr) )
However, after 12 hours it's still crunching.
Any suggestions?
UPDATE 1: Let's consider the following graph
library(igraph)
G <- graph.formula(1-+2,1-+3,2-+4,2-+5,3-+6,5-+7,7-+8,8-+9,9+-7, 9-+10,
6-+9,1-+5,3-+9,10-+11,11-+12,11-+5,12-+4,4-+10,10-+4,11-+10)
V(G)$attr = c(1,1,0,0,1,0,1,0,1,0,1,0)
plot(G, vertex.label.color = "white", edge.width=E(G)$weight, layout = layout.circle(G))
and the desired outcome should be this...
sapply( ego(G,1,V(G),mode = 'all',mindist = 1), function(v) sum(V(G)[v]$attr) )
[1] 2 2 2 1 4 1 2 2 1 2 1 1
@Tamás, I tried to access the neighbors function without using a loop, but instead of the outcome described above I got this...
sapply(neighbors(G,V(G)),function (v) sum(V(G)[v]$attr))
2 3 5
1 0 1