Hi Yvonne,

The easiest would be to create a dataframe that already contains the edge
attributes, and then pass that data frame to graph.data.frame(). Would that
work for you? You can use merge() to merge the original data frame with the
edge list and the additional data frame containing the attributes. See the
documentation of ?merge for more details.


T.

On Tue, Jan 24, 2017 at 4:21 PM, Yvonne Hegele <
yvonne.heg...@uni-konstanz.de> wrote:

> 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
>
>
> _______________________________________________
> igraph-help mailing list
> igraph-help@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>
_______________________________________________
igraph-help mailing list
igraph-help@nongnu.org
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to