我有一个包含多个组件的网络,我想:
玩具示例:
g <- graph(c("a","b","b","c","c","a","f","g","h","g"))
result_g <- graph(c("f", "g","h","g"))
答案 0 :(得分:1)
为此,您可以先使用components
函数将图形拆分为连接的组件。然后,您可以测试每个组件以查看它是否是完整的子图。当且仅当边的数量等于n(n-1)/ 2时,图才是满的,其中n是节点数。因此,使用您的示例:
CompList = components(g)
NotFull = c()
for(i in 1:CompList$no) {
COMP = induced_subgraph(g, which(CompList$membership==i))
VC = vcount(COMP)
if(ecount(COMP) != VC*(VC-1)/2) {
NotFull = c(NotFull, which(CompList$membership==i)) }
}
result_g = induced_subgraph(g, NotFull)
result_g
IGRAPH 5d61ea5 DN-- 3 2 --
+ attr: name (v/c)
+ edges from 5d61ea5 (vertex names):
[1] f->g h->g