Count how many vertices in a vertex's neighbourhood have an attribute in igraph for R
问题 I have a large graph (several, actually) in igraph—on the order of 100,000 vertices—and each vertex has an attribute which is either true or false . For each vertex, I would like to count how many of the vertices directly connected to it have the attribute. My current solution is the following function, which takes as its argument a graph. attrcount <- function(g) { nb <- neighborhood(g,order=1) return(sapply(nb,function(x) {sum(V(g)$attr[x]})) } This returns a vector of counts which is off