[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] getting the graph of the maximum component
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] getting the graph of the maximum component |
Date: |
Sun, 8 Aug 2010 21:42:57 +0200 |
Hi Martin,
On Sat, Aug 7, 2010 at 3:20 PM, Martin Tomko <address@hidden> wrote:
> Hi All,
> I have a graph that consists of many disconnected components (subgraphs, or
> clusters...).
> 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 :
>
> c<-clusters(g)
> which.max(c$csize)
>
> I would like to get it as a graph object. trying the following failed:
> gg<-c[which.max(c$csize)]
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:
>
> f<-decompose.graph(g)
> ff<-f[1]
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
single-element list.
So f[[1]] 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.
Best,
Gabor
> length(V(ff)) claiming that ff is not a graph object (typeof shows that it
> is a list of graph objects).
>
> Thanks
> Martin
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
--
Gabor Csardi <address@hidden> UNIL DGM
- [igraph] peeling off graphs - minimum spanning tree traversal, Martin Tomko, 2010/08/06
- Re: [igraph] peeling off graphs - minimum spanning tree traversal, Tamas Nepusz, 2010/08/06
- [igraph] getting the graph of the maximum component, Martin Tomko, 2010/08/08
- Re: [igraph] getting the graph of the maximum component, Claudia Muller-Birn, 2010/08/08
- Re: [igraph] getting the graph of the maximum component,
Gábor Csárdi <=
- Re: [igraph] getting the graph of the maximum component, Martin Tomko, 2010/08/09
- Re: [igraph] getting the graph of the maximum component, Gábor Csárdi, 2010/08/09
- Re: [igraph] getting the graph of the maximum component, Martin Tomko, 2010/08/09
- Re: [igraph] getting the graph of the maximum component, Gábor Csárdi, 2010/08/09
- Re: [igraph] getting the graph of the maximum component, Martin Tomko, 2010/08/09
- Re: [igraph] getting the graph of the maximum component, Gábor Csárdi, 2010/08/09
- Re: [igraph] getting the graph of the maximum component, Martin Tomko, 2010/08/09
- Re: [igraph] peeling off graphs - minimum spanning tree traversal, Martin Tomko, 2010/08/08