igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] igraph R: vertices and attributes do not match


From: Yvonne Hegele
Subject: [igraph] igraph R: vertices and attributes do not match
Date: Tue, 24 Jan 2017 16:21:14 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Thunderbird/45.6.0

Hello everyone,

I have a problem which seems easy but I could absolutly not find a solution for it, so I would very much appreciate your help:

I have an edgelist containing a number of edges with named IDs. I imported this data ("edgelist") and created a igraph object in R  using the code:
network <- graph.data.frame(edgelist)

Second, I imported a matrix of attributes ("attributes") into R containing the IDs of the edges (as used in edgelist) as first column and further columns with other attributes. To attache these attributes, I used the code (from https://sna.stanford.edu/lab.php?l=1)

for (i in V(network)) {
  for (j in names(attributes)) {
    network <- set.vertex.attribute(network,
                                       j,
                                       index = i,
                                       attributes[i, j])
  }
}

Unfortunately, in the edgelist some edges are not senders but R sorted the edges according to their appearence in the edgelist which now differs from the order in the attributes matrix. Hence my problem is now that the attributes are not matched correctly upon the vertices in the igraph network. Unfortunately, there is no easy way how to sort the attribute matrix in the same order than the igraph network did automatically (Or is this the easieast way and you know one?)

So I tried to create an empty graph and fill in the information one after the other: 
network <- graph.empty()
First the 171 vertices as their IDs
add.vertices(network,171,"name", attr = list(as.character(attributes$ID)))
This however produces the following error message:
Error in add.vertices(network, 171, "name", attr = list(as.character(attributes$ID))) : 
  please supply names for attributes

In the next step I hoped to include the edges as in edgelist into this listing of edges with add.edges. But I am not sure if this was successful in recognizing the correct IDs for the edges and attributes.

Could you please help me working around this problem?

Many thanks!
Yvonne


  


reply via email to

[Prev in Thread] Current Thread [Next in Thread]