![](/img/trans.png)
[英]R and igraph: subgraph nodes based on attributes of other nodes that are incident on edge
[英]Selecting clusters based on number of nodes iGraph/R
有没有一种方法可以选择簇具有最大顶点数的子图/子集?
本质上,我想做类似的事情:
want <- components(X)$csize < 20
我考虑过将群集ID从图形数据帧合并到节点df,然后使用计数或类似方法将原始df子集化,然后再次计算图形数据帧。
这是使用随机图的潜在解决方案。 您将需要使用groups
的components
,以确定哪些节点属于哪个组件 ,那么你将需要使用length
确定该分量有多大:
set.seed(4321)
g <- sample_gnm(100, 40, F, F)
plot(g, vertex.size = 5, vertex.label = '')
want <- g %>%
components %>%
groups %>%
.[sapply(., length) > 3]
want
将提供以下内容:
$`1`
[1] 1 34 38 45 75
$`3`
[1] 3 12 24 39 50 54 58 60 67 84 97 99 100
$`5`
[1] 5 35 37 41 44 53 65 90
然后,你可以删除不包括在所有节点want
newG <- g %>%
{. - V(.)[! as.numeric(V(.)) %in% unlist(want)]}
plot(newG, vertex.size = 5, vertex.label = '')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.