[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [igraph] weighted graph

**From**: |
Csardi Gabor |

**Subject**: |
Re: [igraph] weighted graph |

**Date**: |
Wed, 29 Aug 2007 20:12:45 +0200 |

**User-agent**: |
Mutt/1.5.9i |

Simone,
it seems to be easy to determine the multiplicity of the edges in
an edge list, but all i can think of is converting the edge list
to a character vector by making "i j" from an i j edge. You need to
be sure that i<=j for every edge. This is always true if the edgelist
is created by get.edgelist. So it is something like:
>* g <- graph( c(0,1,0,1,0,1,0,2,0,2), dir=FALSE)*
>* el <- get.edgelist(g)*
>* el <- apply(el, 1, function(x) paste(x, collapse=" "))*
>* el <- table(el)*
>* el2 <- as.numeric(unlist(strsplit(names(el), " ")))*
>* el3 <- unname(el)*
>* g2 <- graph(el2, dir=is.directed(g))*
>* E(g2)$weight <- el3*
>* print(g2, e=T)*
Vertices: 3
Edges: 2
Directed: FALSE
Edges and their attributes:
weight
[0] 0 -- 1 3
[1] 0 -- 2 2
Actually there is a count.multiple function in the development branch
of igraph, that could make things much easier.
Hope this helps,
Gabor
On Wed, Aug 29, 2007 at 04:45:02PM +0200, Simone Gabbriellini wrote:
>* dear list,*
>* *
>* I have an igraph object with multiple edges.*
>* I would like to simplify it, using simplify(), but I don't like to *
>* loose all that information;*
>* I have all my data in edgelist format, so I am wondering if it's *
>* possible, while I read it with read.graph(), to convert multiple *
>* edges into one weighted edge.*
>* *
>* I'm thinking about something like:*
>* *
>* 1 2*
>* 1 2*
>* 1 3*
>* 1 5*
>* *
>* into*
>* *
>* 1 2 weight=2*
>* 1 3*
>* 1 5*
>* *
>* thank you,*
>* Simone*
>* *
>* *
>* _______________________________________________*
>* igraph-help mailing list*
>* address@hidden*
>* http://lists.nongnu.org/mailman/listinfo/igraph-help*
--
Csardi Gabor <address@hidden> MTA RMKI, ELTE TTK