igraph获取已连接组件的ID [英] igraph get ids of connected components
本文介绍了igraph获取已连接组件的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在igraph
中访问图形的前3个相连组件的ID?
How can I access the ids of the top3 connected components of a graph in igraph
?
c <- igraph::components(g, mode = 'weak')
which(c$membership == which.max(c$csize))
将给出最大的 和
which(c$membership == which.max(c$csize-1))
与c$csize-1
相同的结果将从所有值中减去-1.
the same result as c$csize-1
will just subtract -1 from all values.
推荐答案
您可以使用order
来排序和找出前3个最大群集的成员资格,并使用%in%
检查顶点是否在其中之一内:
You can use order
to sort and find out the memberships of the top 3 largest clusters and use %in%
to check if vertices are within one of them:
which(c$membership %in% order(c$csize, decreasing = TRUE)[1:3])
-
order(c$csize, decreasing = TRUE)
给出索引(对应于群集ID),该索引将对size
进行降序排序; -
c$membership
包含所有顶点的聚类ID; - 使用
%in%
检查群集ID是否在前三名之内; order(c$csize, decreasing = TRUE)
gives the index(which corresponds to the cluster id) that will sort thesize
in descending order;c$membership
contains the cluster id for all vertices;- use
%in%
to check if the cluster id are within the top three;
这篇关于igraph获取已连接组件的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文