[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Creating subgraphs on the basis of clusters()
From: |
Gabor Csardi |
Subject: |
Re: [igraph] Creating subgraphs on the basis of clusters() |
Date: |
Fri, 14 Dec 2007 10:35:02 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
On Fri, Dec 14, 2007 at 11:35:40AM +0900, MATSUDA, Noriyuki wrote:
> Hello:
>
> I need help in creating subgraphs by selecting clusters of certain sizes.
> To
> do so, I want to obtain the list of memberships of the vertices to be
> selected.
> -------------------------------------------------------------------------------------------------------------------
> a <- c(0,1)
> b <- c(2,3,3,4)
> c <- c(5,6,5,7,6,7)
> d <- c(8,9,8,10,8,11, 9,10,9,11, 10,11)
> e <- c(12,13,12,15, 13,14, 14,15, 15,16)
> g<- graph(c(a,b,c,d,e),directed=F)
> plot(g, layout= layout.circle) #vertex.label=V(g)$name
> cls<- clusters(g)
> # $membership
> # [1] 0 0 1 1 1 2 2 2 3 3 3 3 4 4 4 4 4
> # $csize
> # [1] 2 3 3 4 5 #e.g., the membership & the size of the first
> cluster are 0 & 2
>
> clsID<- which(cls$size == 2) - 1 # resulting in a single value 0
> which(cls$membership == clsID) # 1, 2
> clsID<- which(cls$csize == 3) - 1 # resulting in a vector consisted of 1 &
> 2
> which(cls$membership == clsID) # resulting in 0 0 which are hard to
> interpret.
clsID <- which(cls$size==n) - 1
gives you the cluster ids of the clusters with 'n' vertices, i think that
is clear. Then
which(cls$membership == clsID)
is not a very good idea, since it uses R's recycling rule and if
clsID is longer than 1 then it is not what you want. Eg. try:
a <- 1:4
a == 1
a == c(1,2)
a == c(2,1)
I think what you want is
which(cls$membership %in% clsID) - 1
This gives the vertex ids in the clusters clsID.
Gabor
> -------------------------------------------------------------------------------------------------------------------
>
> Is there a way to specify the condition like cls$membership in clsID ?
> --
> MATSUDA, Noriyuki <in Kanji> 松 田 紀 之
[...]
--
Csardi Gabor <address@hidden> MTA RMKI, ELTE TTK