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

835 views Asked by At

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

There are 1 answers

3
lukeA On BEST ANSWER

Try V(igObject)[which.max(gCloseness)]