igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] quick way to load bipartite graphs


From: Simone Gabbriellini
Subject: Re: [igraph] quick way to load bipartite graphs
Date: Thu, 31 Jan 2013 13:55:21 +0100

Dear Tamas,

I have found something that works. I post it here in the hope it could
be useful:

# load file
net<-as.matrix(read.csv(nets[1]))
# manipulate it a bit
net<-apply(net,2,as.character)
net[,1] <- sub("^", "t", net[,1])
net[,2] <- sub("^", "u", net[,2])
# make the graph
g<-graph.edgelist(net[,-3], directed=F)
# add weights
E(g)$width<-net[,3]
# add type
V(g)$type<-grepl("t",V(g)$name)

Best,
Simone

2013/1/31 Tamas Nepusz <address@hidden>:
> 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
>>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help



-- 
Simone Gabbriellini, PhD

address@hidden, University of Bologna
mobile: +39 340 39 75 626
email: address@hidden
home: www.digitaldust.it

DigitalBrains srl
Amministratore
mobile: +39 340 39 75 626
email: address@hidden
home: www.digitalbrains.it



reply via email to

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