igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Inter and intra vertices' attribute value using subgraph


From: Tamás Nepusz
Subject: Re: [igraph] Inter and intra vertices' attribute value using subgraph
Date: Fri, 26 Aug 2011 16:51:15 +0200

Dear Ali,

> If I understand Sugraphs correctly, it returns vertices with attributes and 
> edges which satisfy some rule based on either the index or the regular 
> expression of any kind. I don't seem to have the desired results when I run 
> the following code over my graph.
> 
> celticgroup <- which(V(g)$group == "CELTIC")
> subg <- subgraph(g, celticgroup)
I think you are bitten by the classical "indices-off-by-one" bug here. The R 
interface of igraph indexes the vertices from zero up to 0.5.5, but R uses a 
1-based indexing. Therefore, you have to subtract 1 from "celticgroup" before 
passing it to subgraph().

> As I am interested in inter attribute level links as well, I would like to 
> know how to do that - all edges which have "CELTIC" in either the source or 
> the target vertex. I do not know how to get this calculated.
> Could anyone please share some insight here?
Try something like:

celticgroup <- which(V(g)$group == "CELTIC") - 1
E(g)[celticgroup %--% V(g)]

The trick here is the %--% operator; see the following page for an explanation:

http://igraph.sourceforge.net/doc/R/iterators.html

-- 
T.




reply via email to

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