[R] Calculating Betweenness - Efficiency problem
Gabor Csardi
csardi at rmki.kfki.hu
Wed Jul 23 12:43:51 CEST 2008
Senthil,
sending a 12Mb file to the list is not a good idea.
I've run the code in my previous email without any problem, so you need
to be a bit more specific about what went wrong for you.
This is what I get:
> library(igraph)
> tab <- read.csv("/tmp/Test.csv")
> dim(tab)
[1] 304711 2
> length(unique(tab))
[1] 2
> g <- graph.data.frame(tab)
> summary(g)
Vertices: 48072
Edges: 304711
Directed: TRUE
No graph attributes.
Vertex attributes: name.
No edge attributes.
> system.time(bet <- betweenness(g))
user system elapsed
661.180 0.098 661.716
> length(bet)
[1] 48072
> bet <- data.frame(city=V(g)$name, betweenness=bet)
> dim(bet)
[1] 48072 2
Best,
Gabor
On Tue, Jul 22, 2008 at 11:58:37AM -0700, Senthil Purushothaman wrote:
> Dear Gabor,
> Thank you very much for the insights. I have been using the igraph
> package for my computations. But I did not know about
> graph.data.frame(). Thanks again for that. So I did run my data using
> the steps you had provided. Weirdly, even though the .csv file has
> approximately 300,000 records (remember that the file gets truncated to
> 65536 rows when opened in Excel 2003), not all of them are pulled in
> during the operation and the final betweenness list contains only ~1000+
> records but it should be tens of thousands.
>
> I know that you are a busy person. This problem seems to be a very
> different challenge. I am attaching the Test.csv file for your
> experiments. Thank you very much again.
>
> Best regards,
> Senthil
> (909) 267-0799
>
> -----Original Message-----
> From: Gabor Csardi [mailto:csardi at rmki.kfki.hu]
> Sent: Monday, July 21, 2008 1:57 AM
> To: Senthil Purushothaman
> Cc: jim holtman; r-help at r-project.org
> Subject: Re: [R] Calculating Betweenness - Efficiency problem
>
> Senthil,
>
> you can try the 'igraph' package. Export your two-column Excel file
> as a .csv, use 'read.csv' to read that into R, then 'graph.data.frame'
> to create an igraph graph from it. Finally, call 'betweenness' on
> the graph. It is really just three/four lines, something like this:
>
> tab <- read.csv(...)
> g <- graph.data.frame(tab)
> bet <- betweenness(g)
> bet <- data.frame(city=V(g)$name, betweenness=bet)
>
> The last line creates a two column data frame with the betweenness
> score of each city.
>
> Best,
> Gabor
[...]
--
Csardi Gabor <csardi at rmki.kfki.hu> UNIL DGM
More information about the R-help
mailing list