Extracting an edge list from a network object

I've been using the statnet suite of tools a lot recently.  As with any powerful software, there is quite a learning curve.  I will write some notes in my blog to help me remember tricks that I learn along the way.  And who knows? They might even be useful to other people!

For a variety of reasons, we have found it easy to import our networks as adjacency matrices.  The problem is that when there are attributes associated with the edges, it is much easier to deal with an edge list.  While using summary(net) yields an edge list as part of the summary, it was not clear to me how to get such a list as a manipulable object.  I wrote the statnet_help list and Carter Butts (co-author of network) pointed out to me that getting an edgelist is quite simple. Having read in our adjacency matrix

  1. mat <-read.table("mat5.txt",header=TRUE)
  2. mat <- as.matrix(mat)
  3. net <- network(mat, directed=FALSE)

We can get the edge list like this:

  1. bbb <- as.matrix(net,matrix.type="edgelist") 


4 thoughts on “Extracting an edge list from a network object”

  1. This is helpful, thanks. But once the edgelist is created, how do I associate the attribute file with it?

  2. Hi,
    I'm trying to find information on a similar problem. I'm not sure how to import an edgelist into R for analysis with igraph or sna. Currently my data is in the following format:
    774347 450679 0.02703
    774347 966680 0.02703
    929066 450679 0.25
    450679 774347 0.04545
    450679 929066 0.04545
    450679 657045 0.04545
    450679 370442 0.04545
    268696 370442 0.22222

    The first two columns are the vertex identifiers.

  3. Not exactly sure, but there is an option in igraph to import a raw edgelist with not header information. If you save your edgelist locally, then it seems like you can very easily do the following:

    net <- read.graph("myfile.txt", format = "edgelist") I am not an expert on igraph, but this seems like it should work (or at least some variant on it).

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>