2016-03-18 43 views
0

更大程度中心頂點我想使用的igraph R中的最高度中心的頂點,我試着用:如何獲得與IGRAPH

V(g)[degree(g,V(g)$id) == which.max(degree(g))] 

但它不工作。

回答

0

嘗試

library(igraph) 
set.seed(5) 
g <- ba.game(100) 
V(g)$id <- paste0("id", 1:100) 
(idx <- which(degree(g)==max(degree(g)))) 
V(g)$id[idx] 
# [1] "id1" "id2" 

# optional plot 
cols <- rep("blue", vcount(g)); cols[idx] <- "red"; plot(g, vertex.shape="none", vertex.label.color=cols, edge.arrow.size=.5) 
+0

好,它的工作原理。 獲得id後,如何獲取頂點屬性(例如標籤)。 此語法不起作用: V(g)$ label [which(V(g)$ id == id)] –

+0

'V(g)$ label [idx]'。 – lukeA

+0

它的工作原理,謝謝@lukeA –