igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] How to use contract.vertices() on empty string


From: Gábor Csárdi
Subject: Re: [igraph] How to use contract.vertices() on empty string
Date: Fri, 22 Nov 2013 22:18:58 -0500

You have an NA in category_attr, so igraph does not know what to do
with that vertex. (The error message is terrible, though....)

> category_attr
    Dev Traffic  Energy    <NA>     Dev
      1       2       3      NA       1

Gabor

On Fri, Nov 22, 2013 at 10:15 PM,  <address@hidden> wrote:
> I have a network I would like to contract over the attribute 'category'. BUT
> some vertices take the value "" (empty string) for the attribute category.
> This makes contract.vertices() gives the error:
>
>   Error in contract.vertices(pg$proj2, category_attr) :
>     At structure_generators.c:84 : Invalid (negative) vertex id, Invalid
> vertex id
>
> What's the best strategy to avoid this error? (Note that I can't replace
> 'category' with 'NA', which for the vertices type=FALSE takes another
> meaning in my network.)
>
> I was able to replicate my situation in a MWE
>
> id <- c("www.user_a.com","www.user_b.com",
>         "www.user_c.com","www.user_d.com",
>         "www.user_e.com","www.thread_1.com",
>         "www.thread_2.com","www.thread_3.com",
>         "www.thread_4.com","www.thread_5.com")
> type <- c(FALSE,FALSE,
>           FALSE,FALSE,
>           FALSE,TRUE,
>           TRUE,TRUE,
>           TRUE,TRUE)
> name <- c("user_a","user_b",
>           "user_c","user_d",
>           "user_e","thread_1",
>           "thread_2","thread_3",
>           "thread_4","thread_5")
> category <- c(NA,NA,
>               NA,NA,
>               NA,"Dev",
>               "Traffic","Energy",
>               "","Dev")
>
> nodes <- data.frame(id,name,type,category)
>
> from <- c("www.user_a.com","www.user_b.com",
>           "www.user_c.com","www.user_d.com",
>           "www.user_e.com","www.user_d.com",
>           "www.user_c.com","www.user_b.com",
>           "www.user_a.com","www.user_e.com",
>           "www.user_c.com","www.user_e.com")
> to <-c("www.thread_1.com","www.thread_2.com",
>        "www.thread_3.com","www.thread_4.com",
>        "www.thread_5.com","www.thread_1.com",
>        "www.thread_2.com","www.thread_3.com",
>        "www.thread_4.com","www.thread_5.com",
>        "www.thread_5.com","www.thread_1.com")
>
> edges <- data.frame(from,to)
>
> g <- graph.data.frame(edges, directed=TRUE, vertices=nodes)
>
> pg <- bipartite.projection(g)
>
> category_attr <- get.vertex.attribute(pg$proj2, "category")
>
> map = setNames(c(1:4), c("Dev","Traffic","Energy",""))
>
> category_attr <- map[unlist(category_attr)]
>
> igraph_category <- contract.vertices(pg$proj2, category_attr)
>
> ## Error in contract.vertices(pg$proj2, category_attr) :
> ## At structure_generators.c:84 : Invalid (negative) vertex id, Invalid
> vertex id
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help



reply via email to

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