Hi Sam, 

If I understood it right, community.ml is the result of the community detection 
algorithm. In this case, you can simply use tapply:

tapply(V(g)$count, membership(community.ml), FUN=sum)

where g is your graph. V(g)$count gives you the value of the "count" vertex 
attribute for each vertex, and tapply() applie the given function (i.e. sum) to 
groups of vertices where the groups are defined by the membership vector. 

-- 
T.


On Friday, 17 August 2012 at 18:16, Sam Steingold wrote:

> I have a graph with some vertex attributes:
> 
> IGRAPH UNW- 9105 1110486 -- 
> + attr: name (v/c), count (v/n), weight (e/n)
> 
> and I have a community structure on it.
> how do I compute, say, the vector of sums of counts (vertex attribute)
> of communities?
> 
> so far I only came up with
> 
> sapply(1:length(community.ml), function (i) sum(vertices[vertices$vertex %in% 
> attr(which(membership(community.ml) == i),"names"),]$count))
> 
> where `vertices' is a data frame which was used to create the graph in
> 
> graph.data.frame(edges.all, vertices = vertices)
> 
> I suspect that there is a better way.
> what is it?
> 
> -- 
> Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 
> 11.0.11103000
> http://www.childpsy.net/ http://dhimmi.com http://mideasttruth.com
> http://thereligionofpeace.com http://openvotingconsortium.org
> If you misspell "milk" 4 times, you can get "beer".
> 
> _______________________________________________
> igraph-help mailing list
> [email protected] (mailto:[email protected])
> https://lists.nongnu.org/mailman/listinfo/igraph-help




_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to