2012-12-11 33 views
1

在igraph中是否有函數來計算no。以及基於屬性的每個連接組件的大小。 即。通過它們的屬性「連接」頂點的子集。連接長度

library(igraph) 
## create example graph 
g1 <- graph.full(5) 
V(g1)$name <- 1:5  
g2 <- graph.full(5) 
V(g2)$name <- 6:10 
g3 <- graph.ring(5) 
V(g3)$name <- 11:15 
g <- g1 + g2 + g3 + edge('1', '6') + edge('1', '11') 

##defining attribute to subset of vertices 
hh<-1:vcount(g) %in% c(7,6,1,13,14) 
g<-set.vertex.attribute(g, name="selected" ,value=0) 
g<-set.vertex.attribute(g, name="selected",hh, value=1) 

#plotted out 
vc="[<-"(rep('black',vcount(g)),c(7,6,1,13,14),'red') 
plot(g,vertex.color=vc, vertex.label.color="white") 

什麼,我可以在這一刻想到的是僅使用選定的頂點regraph和運行clusters功能。有一個更簡單的方法嗎?

+0

抱歉,但我不明白你想要什麼到底是什麼?你能解釋這個函數的輸出嗎? – agstudy

回答

2

您可以使用induced.subgraphsubgraph取決於你的igraph優化版本

 clusters(induced.subgraph(g,V(g)[V(g)$selected == 1])) 

$membership 
[1] 1 1 1 2 2 

$csize 
[1] 3 2 

$no 
[1] 2 
+0

@WesleyGoi對你的問題做了這個答案嗎? – agstudy

+0

是的,謝謝你對indu.subgraph的建議,非常感謝! – Buthetleon