2015-06-15 26 views
0

我使用igraph包在R上工作的圖形。我得到親密度中心性與igraph方法,我想找到與名稱密切的最大值。r - 如何找到Max vlaue的名字在Closeness Centrality igraph輸出

library(igraph) 
# Create of Graph Matrix for Test Closeness Centrality 
g <- read.table(text="A B 
    1 2 
    2 3 
    3 4 
    4 5", header=TRUE) 
gadj <- get.adjacency(graph.edgelist(as.matrix(g), directed=FALSE)) 
igObject <- graph.adjacency(gadj) # convert adjacency matrix to igraph object 
gCloseness <- closeness(igObject) # Assign Closeness to Variable for print 

當我使用的max()我得到貼近的最大值,當使用names()回NULL。

> max(gCloseness) 
    [1] 0.1666667 

其他:

> names(max(gCloseness)) 
    NULL 

回答

0

嘗試V(igObject)[which.max(gCloseness)]

+0

只顯示值,我的結果是: 「頂點序列:[1] 4」 –

+0

的輸出爲'V(igObject)[其。 max(gCloseness)]''你的示例數據是'3'。如果你標記節點,我會是標籤,例如for'V(igObject)$ name < - letters [1:5]; V(igObject)[which.max(gCloseness)]'輸出是'c' – lukeA

+0

是的!謝謝。我的訓練數據沒有標籤。我測試另一個數據集是正確的。 –