[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] quick way to load bipartite graphs
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] quick way to load bipartite graphs |
Date: |
Thu, 31 Jan 2013 13:47:09 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 |
Dear Simone,
I would probably do it as follows:
1. Import the CSV file as a data frame
2. Recode the "topic" column to use IDs like "t_696", "t_698", "t_717" and
so on.
3. Recode the "user" column to use IDs like "u_2", "u_9" and so on.
4. Use graph.data.frame to construct a graph.
5. Add a "type" vertex attribute to the constructed graph such that vertices
whose name starts with "t_" gets type 0, while the rest gets type 1. This
makes the graph bipartite to igraph.
Best,
Tamas
On 01/31/2013 11:32 AM, Simone Gabbriellini wrote:
> Dear List,
>
> I have a bunch of files where info about bipartite networks are coded this
> way:
>
> "topic","user","weight"
> 696,2,1
> 696,9,2
> 696,17,1
> 696,137,1
> 698,9,3
> 698,17,3
> 717,3,1
> 717,5,1
> 717,8,1
> 717,9,8
>
>
> is there any straightforward way to load one of this files and create
> a bipartite network with edge weights? Consider that there could be an
> overlap between numbers in the first and second column.
> Right now, I only have this code:
>
> net<-as.matrix(read.csv("my file"))
> g<-graph.edgelist(net[,-3])
>
> Any help much appreciated.
>
> Best,
> Simone
>