簡體   English   中英

根據節點數iGraph / R選擇集群

[英]Selecting clusters based on number of nodes iGraph/R

有沒有一種方法可以選擇簇具有最大頂點數的子圖/子集?

本質上,我想做類似的事情:

want <- components(X)$csize < 20  

我考慮過將群集ID從圖形數據幀合並到節點df,然后使用計數或類似方法將原始df子集化,然后再次計算圖形數據幀。

這是使用隨機圖的潛在解決方案。 您將需要使用groupscomponents ,以確定哪些節點屬於哪個組件 ,那么你將需要使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM