[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] efficiency in reading a CSV file
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] efficiency in reading a CSV file |
Date: |
Thu, 3 Jun 2010 23:55:15 +0100 |
> Disclaimer: I'm not a proficient programmer.
Disclaimer: neither am I and I don't even use R frequently, so there might be a
better solution than the ones I propose here. :)
> for (aut in auts) {
> if (!(aut %in% vertices)) vertices <- c(vertices,aut)
> }
As I can see, you can avoid having to use a for loop here if you write
something like this:
vertices <- c(vertices, aut[!aut %in% vertices])
> if (length(auts)>1) {
> collpairs <- combn(auts,2)
> for (i in 1:length(collpairs[1,])) {
> collpair <- sort(collpairs[,i])
> if (!(list(collpair)%in%edges)) edges <- c(edges,list(collpair))
> }
> }
Here I wouldn't waste time by calling sort() on each column of collpairs; I
would simply write this:
edges <- c(edges, combn(auts, 2))
This would obviously create multiple edges in your network, but you can simply
get rid of them by calling igraph::simplify() on the graph, which should be
faster than the trickery with the for loops.
--
Tamas