Re: [R] vertex labels in igraph from adjacency matrix

From: Charilaos Skiadas <>
Date: Wed, 05 Mar 2008 02:27:21 -0500

On Mar 5, 2008, at 1:39 AM, Mark W Kimpel wrote:

> I am getting some unexpected results from some functions of igraph and
> it is possible that I am misinterpreting the vertex numbers. Eg., the
> max betweenness measure seems to be from a vertex that is not
> connected
> to a single other vertex. Below if my code snippet:
> require(igraph)
> my.graph <- graph.adjacency(adjmatrix = my.adj.matrix, mode=c
> ("undirected"))
> most.between.vert <- colnames(my.adj.matrix)[which(betweenness(graph =
> my.graph, v=V(my.graph), directed = FALSE) == max(betweenness(graph =
> my.graph, v=V(my.graph), directed = FALSE))) + 1]

What is the +1 for? Seems to me that this would give you the wrong vertex, since you find the vertex which is the max, and then you ask it to give you the next vertex in the list.

Btw, you will likely want to take the betweenness call out, and call it once and store the result, instead of calling it twice (well, assuming the graph is largish). Or even better, use which.max:

which.max(betweenness(graph = my.graph, v=V(my.graph), directed = FALSE)) Haris Skiadas
Department of Mathematics and Computer Science Hanover College

> sum(my.adj.matrix[most.between.vertext,])
> 0
> Is there a way to automatically set the vertex name attributes from
> the
> row and colnames of the inputted adjacency matrix to graph.adjacency?
> This would seem like an intuitive feature, but I can't find it
> documented. In the absence of this feature, how can I make sure that I
> am setting the vertex name attributes correctly?
> --
> Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
> Indiana University School of Medicine
> 15032 Hunter Court, Westfield, IN 46074
> (317) 490-5129 Work, & Mobile & VoiceMail
> (317) 204-4202 Home (no voice mail please)
> mwkimpel<at>gmail<dot>com
> mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 05 Mar 2008 - 07:31:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 05 Mar 2008 - 09:30:18 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive