igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] getting the graph of the maximum component


From: Martin Tomko
Subject: Re: [igraph] getting the graph of the maximum component
Date: Mon, 09 Aug 2010 09:56:48 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100227 Lightning/1.0b1 Thunderbird/3.0.3

Hi Gabor,#
thanks a lot, that helps heaps. I tend to forget the R tricks, I don't work with it on a daily basis. Just one question - you note that igraph has 0-based indexing (as opposed to R starting with 1). I just want to make sure I get this right, it can potentially mean that I missed some data in my processing. Where is it manifested, or where can I find it documented?

Oh, and BTW, igraph rocks! :)
Cheers
Martin


On 8/8/2010 9:42 PM, Gábor Csárdi wrote:
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





--
Martin Tomko
Postdoctoral Research Assistant

Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland

email:  address@hidden
site:   http://www.geo.uzh.ch/~mtomko
mob:    +41-788 629 558
tel:    +41-44-6355256
fax:    +41-44-6356848




reply via email to

[Prev in Thread] Current Thread [Next in Thread]