2011-09-20 43 views
0

我想從我的圖中收集一些社區。然而,由此產生的社區由孤立的節點構成,這與我對社區的理解相矛盾。 這是我必不可少的R/IGRAPH代碼:在孤立節點中檢測社區結果

g<-simplify(g) 
print("isolates: ") 
length(which(degree(g)==0)-1) # says 0 

c<-fastgreedy.community(g) 

cmem<-community.to.membership(g,c$merges,3081) 
w<-which(cmem$membership==0) 
sub<-subgraph(g,w) 

print("isolates in subgraph: ") 
length(which(degree(sub)==0)-1) # says > 0 

難道我犯了一個錯誤?感謝您的幫助。

回答

1

您忘記了從which(cmem$membership == 0)減去1,這是因爲igraph從零索引節點所需要的,而R使用基於1的索引。用w <- which(cmem$membership == 0) - 1再試一次,看看分離株是否存在。

+0

非常感謝。這有幫助! – Julian