igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] adding vertices and edges to an empty graph from R


From: Gábor Csárdi
Subject: Re: [igraph] adding vertices and edges to an empty graph from R
Date: Fri, 12 Dec 2008 09:15:27 +0100

Hi, this is a common igraph catch, the vertices are numbered from zero.
You need

g <- add.edges(g, rbind(ea, 21)-1)

Gabor

On Thu, Dec 11, 2008 at 11:34 PM, Rajarshi Guha <address@hidden> wrote:
> Hi, I'm using igraph from R and am a little confused on how I can manually
> generate graphs by adding nodes and edges.
>
> I have the following code:
>
> g <- graph.empty(0, directed=FALSE)
>
> ea <- 1:10
> eb <- 11:20
>
> g <- add.vertices(g, 10)
> g <- add.vertices(g, 10)
> g <- add.vertices(g, 1)
>
> g <- add.edges(g, as.numeric(t(cbind(ea, 21))))
>
> So, I expect that I should add the edges
>
> 1 21
> 2 21
> 3 21
> ...
> 10 21
>
> Instead I get the error:
>
> Error in add.edges(g, as.numeric(t(cbind(ea, 21)))) :
>  At type_indexededgelist.c:244 : cannot add edges, Invalid vertex id
>
> More generally, is there a way to refer to nodes by some label? In the above
> case how would I determine the 'vertex id' - wouldn't they just be the
> values 1, 2, 3, ... 21?
>
> Any pointers would be appreciated
>
>
> -------------------------------------------------------------------
> Rajarshi Guha  <address@hidden>
> GPG Fingerprint: D070 5427 CC5B 7938 929C  DD13 66A1 922C 51E7 9E84
> -------------------------------------------------------------------
> A meeting is an event at which the minutes are
> kept and the hours are lost.
>
>
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM




reply via email to

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