igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Weighted bipartite graphs?


From: Gábor Csárdi
Subject: Re: [igraph] Weighted bipartite graphs?
Date: Sun, 29 Nov 2009 14:50:59 +0100

Dear Uri,

On Mon, Nov 23, 2009 at 9:27 PM, Uri Shwed <address@hidden> wrote:
> Dear Gabor et.al.,
> What would you guys say is the best way to get a bipartite data set with
> meta-data into a weighted projection?
> For example:
>
> data<-data.frame(people=c(1:5,5:8,1),events=c(1,1,1,1,1,2,2,2,2,2),year=c(2004,2004,2004,2004,2004,2005,2005,2005,2005,2005))
>
> desired outcome:
> The first graph projection below (achieved through graph.incidence and
> bipartite.projection), with Edge attribute of weight (giving all edges
> weight of 1 and the edge between 1 and 5 a weight of 2, because they
> attended 2 events together), and an edge attribute of year.
> Any ideas?

I am not sure what you did with graph.incidence, but this is what I would do.

library(igraph)
data<-data.frame(people=c(1:5,5:8,1),events=c(1,1,1,1,1,2,2,2,2,2),year=c(2004,2004,2004,2004,2004,2005,2005,2005,2005,2005))
data2 <- data.frame(people=paste(sep="", "P", data[,1]),
                              events=paste(sep="", "E", data[,2]))
G <- graph.data.frame(data2, dir=FALSE)
V(G)$type <- grepl("^P", V(G)$name)

proj <- bipartite.projection(G)
V(proj[[1]])$name <- V(G)$name[!V(G)$type]
V(proj[[2]])$name <- V(G)$name[V(G)$type]
# We use here that bipartite.projection keeps the order of the vertices
# ideally it should keep the vertex attributes

Unfortunately, there is no way currently to include the "multiplicity"
as edge weight,
at least not easily. But this would be a logical extension, so I will
add it ASAP.

Best,
G.

> $proj1
> Vertices: 8
> Edges: 19
> Directed: FALSE
> Edges:
>
> [0]  0 -- 1
> [1]  0 -- 2
> [2]  0 -- 3
> [3]  0 -- 4
> [4]  0 -- 5
> [5]  0 -- 6
> [6]  0 -- 7
> [7]  1 -- 2
> [8]  1 -- 3
> [9]  1 -- 4
> [10] 2 -- 3
> [11] 2 -- 4
> [12] 3 -- 4
> [13] 4 -- 5
> [14] 4 -- 6
> [15] 4 -- 7
> [16] 5 -- 6
> [17] 5 -- 7
> [18] 6 -- 7
>
> $proj2
> Vertices: 2
> Edges: 1
> Directed: FALSE
> Edges:
>    e
> e [0] 0 -- 1
>
>
> Thanks,
> Uri
>
>
> _______________________________________________
> 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]