igraph-help
[Top][All Lists]

## Re: [igraph] computing community attributes

 From: Tamás Nepusz Subject: Re: [igraph] computing community attributes Date: Fri, 17 Aug 2012 22:19:28 +0200

```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