On Sat, Aug 7, 2010 at 3:20 PM, Martin Tomko<address@hidden> wrote:
I have a graph that consists of many disconnected components (subgraphs, or
I am interested in working with the maximum one.
I figured the following approach to identify it in the csize frame of the
clusters function :
I would like to get it as a graph object. trying the following failed:
What would this do? 'c' is a list with components named 'membership',
'csize' and 'no'. They are not graphs.
The correct way to do it is something like
gg<- subgraph(g, which(c$membership==which.max(c$csize)-1)-1)
The '-1' are because of igraph's zero-based indexing.
seems like decompose.graph could help, but I am wondering what's the easiest
way to identify and get the largest component from this output.
The documentation claims that the result of decompose.graph(g) is a list of
graph objects, but this fails:
This is a common R trap, I guess. If you want to select a single
element of a list, use '[[' for indexing. If you index a list with
'[', you'll select a sub-list, i.e. in your case the result is a
So f[] is a graph, not necessarily the biggest one, of course. If
you want the biggest one, then do it like this:
f[[ which.max(sapply(f, vcount)) ]]
But this is a much slower version than the previous one.
length(V(ff)) claiming that ff is not a graph object (typeof shows that it
is a list of graph objects).
igraph-help mailing list