r - How to find name of Max vlaue in Closeness Centrality igraph output

时间:2015-06-15 14:27:31

标签: r max igraph

I use of igraph package in R for work on graph. I get Closeness Centrality with igraph method, and I want to find maximum value in Closeness with name.

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

When I use of max() I get maximum value of Closeness and when use of names() back NULL.

> max(gCloseness)
  [1] 0.1666667

other:

> names(max(gCloseness))
  NULL

1 个答案:

答案 0 :(得分:0)

尝试V(igObject)[which.max(gCloseness)]