monkey's uncle

notes on human ecology, population, and infectious disease

monkey's uncle header image 2

Extracting an edge list from a network object

September 11th, 2008 · 4 Comments

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

R:
  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:

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

Easy...

Tags: R · Social Network Analysis

4 comments on “Extracting an edge list from a network object

  1. Jennifer on said:

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

  2. I think the answer, if I understand the question correctly, is answered in this post.

  3. David Chen on said:

    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.

  4. jhj1 on said:

    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 *

*

HTML tags are not allowed.