igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Creating subgraphs on the basis of clusters()


From: MATSUDA, Noriyuki
Subject: Re: [igraph] Creating subgraphs on the basis of clusters()
Date: Mon, 17 Dec 2007 09:54:57 +0900

Hello:

   Yes, %in% was what I wanted.  Thanks a lot.
    >  mem<- c(1,2,3,3,4,2,5)
   > which(mem %in% c(3))
   > which(mem %in& c(1,4))

   This will greatly facilitate my analysis.

Nori
At 10:35 AM +0100 07.12.14, Gabor Csardi wrote:
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


_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help


--
MATSUDA, Noriyuki <in Kanji> 松 田 紀 之




reply via email to

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