igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Basic question about data importation


From: Eduardo Urias
Subject: Re: [igraph] Basic question about data importation
Date: Fri, 7 Jan 2011 20:09:36 +0100

Dear Tamas,

I tried your suggestion and it is working now.
Thanks a lot for your help.

My best

2011/1/7 Tamas Nepusz <address@hidden>:
>> I am using igraph from R.
> I'm sure there's an easier way for this in R, but I'm no R expert, and
> this is what I could come up with.
>
> First, I'd read the file using scan() because I never really understood
> how data frames should be indexed and I couldn't make this thing work
> using data frames:
>
> data <- scan("alliance_list.csv", what="string", sep="\n", skip=1)
>
> data now contains every line of the file in a list. Now I split every
> line around the commas, throw away the empty items and enumerate every
> edge within a clique:
>
> data <- lapply(strsplit(data, ","), function(row)
> as.vector(combn(row[row != ""], 2)))
>
> Now all you need to do is to turn your data list into an nx2 matrix:
>
> data <- matrix(unlist(data), nc=2)
>
> and construct a graph out of it:
>
> g <- graph.edgelist(data, directed=F)
>
> V(g)$name then gives you the names of the companies.
>
> --
> T.
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>



-- 
Eduardo Urias
Elabora Consultoria
11 9280 9485   |   11 3124 1517
www.elaboraconsultoria.com.br



reply via email to

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