igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Subsetting graph by edges + building large graph troubles


From: Gábor Csárdi
Subject: Re: [igraph] Subsetting graph by edges + building large graph troubles (R interface)
Date: Wed, 4 Mar 2009 22:18:50 +0100

Hi Steve,

On Wed, Mar 4, 2009 at 9:51 PM, Steve Lianoglou
<address@hidden> wrote:
[...]
> # threshold and directed are defined elsewhere
> graf <- read.graph(filepath, format='ncol', directed=directed)
> good.edges <- E(graf)[weight >= threshold]
> good.graf <- graph(edges, directed=directed)

This is not good. 'good.edges' is just a list of edge IDs here, it is
actually a numeric vector, it is just printed otherwise. What you need
is

bad.edges <- E(graf[ weight < threshold]
good.graf <- delete.edges(graf, bad.edges)

[...]
> # modifed head(E(g), 10) call (modifications in trailing []):
> R> head(E(g), 10)              ## Top 10 lines from file
> [1]  Q0045   -> Q0060  [433]   ## Q0032 YNL182C 433
> [2]  Q0045   -> Q0085  [186]   ## Q0045 Q0060 186
> [3]  Q0045   -> Q0105  [716]   ## Q0045 Q0085 716
> [4]  Q0045   -> Q0110  [997]   ## Q0045 Q0105 997
> [5]  Q0045   -> Q0115  [882]   ## Q0045 Q0110 882
> [6]  Q0045   -> Q0120  [898]   ## Q0045 Q0115 898
> [7]  Q0045   -> Q0130  [928]   ## Q0045 Q0120 928
> [8]  Q0045   -> Q0140  [201]   ## Q0045 Q0130 201
> [9]  Q0045   -> Q0250  [222]   ## Q0045 Q0140 222
> [10] Q0045   -> Q0275  [999]   ## Q0045 Q0250 999

Actually, your graph is correct here. The problem is that E(g) has a
strange way of indexing and 'head' does not now about this. So 'head'
just omits the first (0th, really) edge. Print your first ten edges
with 'E(g)[0:9]' and you will see that it is all right.

> I tried my code on a smaller test file, and it works fine.

My guess is that you didn't use 'head' on the small file.

Btw. there is a function called 'graph.data.frame' which does exactly
what you want, just call it after reading in the table from the file,
and naming your columns c("from", "to", "weight").

[...]

I hope this clarifies things a bit, Best,
Gabor

-- 
Gabor Csardi <address@hidden>     UNIL DGM




reply via email to

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