Re: [R] Converting edgelist to symmetric matrix

From: Gary Weissman <>
Date: Mon, 11 Apr 2011 08:54:55 -0400

Hi Shafique,

If your edgelist is in the form of a text file (elist.csv) that looks like this:

from, to, weight

vertex1, vertex2, 3
vertex2, vertex3, 2.3
vertex4, vertex1, 1.2


you can convert that to a matrix using


edge.list <- read.csv(elist.csv,header=TRUE)

g <-, directed=FALSE)

get.adjacency(g, type="both", attr="weight")

More options for exporting the adjacency matrix are here:

If you give more details about your data format you might get more specific help.


On Apr 11, 2011, at 6:00 AM, wrote:

> ----------------------------------------

>> Date: Sat, 9 Apr 2011 14:34:28 -0700
>> From:
>> To:
>> Subject: [R] Converting edgelist to symmetric matrix
>> Hi,
>> I have network data in the form of a couple of edgelists containing weights in
>> the format "x,y,weight" whereby x represents row header and y represents column
>> header. All edgelists are based on links among 634 nodes and I need to convert
>> them into a 634*634 weighted matrix.

> not find
>> a clue how to do this in R. Any help will be appreciated.

> I'm trying to do something related and found
> ?read.graph
> will format=ncol do what you need? This apparently creates a graph object that likely
> has capacilities you need.? Again, I haven't actually used any of this
> just found while trying to solve a different problem.
> 'It is a simple text file
> with one edge per line. An edge is defined by two symbolic vertex
> names separated by whitespace. (The symbolic vertex names
> themselves cannot contain whitespace. They might followed by an
> optional number, this will be the weight of the edge; the number
> can be negative and can be in scientific notation. If there is no
> weight specified to an edge it is assumed to be zero.
> '
>> Best regards,
>> Shafique

Gary Weissman

	[[alternative HTML version deleted]]

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 11 Apr 2011 - 13:32:42 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 Mon 11 Apr 2011 - 15:10:29 GMT.

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

list of date sections of archive