igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] degrees of separation


From: Gábor Csárdi
Subject: Re: [igraph] degrees of separation
Date: Tue, 21 May 2013 12:57:50 -0400

Hi, please see below.

On Tue, May 21, 2013 at 12:11 PM, Marie Lalanne <address@hidden> wrote:
Hello,

I am a new R and igraph user and I am wondering whether you could give me some hints to do the following:

Assuming 'g' is the graph, 's' the subset and 'v' the vertex:

library(igraph)
data <- "1 2
1 3
2 3
2 5
3 4
3 5
4 5
"
g <- graph.data.frame(read.table(textConnection(data)), 
       directed=FALSE, vertices=data.frame(1:5))
s <- c(1,2)
v <- 4


I have an edgelist (undirected). I would like to compute the following four things:
- for a subset of vertices, the number of edges (without counting twice a same vertex linked with two different vertices of the subset)

So this is effectively the number of vertices connected to s? 

sum(colSums(g[s,-s]) != 0)
 
- for a subset of vertices, if at least one of the vertices from this subset is linked with a particular vertex (from the whole set)

any(g[s,v] != 0)
 
- for a subset of vertices, the minimal degree of separation required to reach a particular vertex (from the whole set)

min(shortest.paths(g, v=4, to=s))
 
- for all the vertices (in the whole set), if they are linked with at least one vertex from the subset

colSums(g[s,]) != 0

Please see the manual, in particular ?'[.igraph' for details.

Best,
Gabor

ps. be critical with my answers, and check them, I haven't checked them too extensively. 


For example:
1-2
1-3
2-3
2-5
3-4
3-5
4-5
and consider the subset of vertices being 1 and 2 and the particular vertex being 4
Answer to the first question: 3 (edges 1-3 and 2-3 are count only for one)
Answer to the second question: 0 (neither 1, neither 2 is directly linked to 4)
Answer to the third question: 2 (edge 1-3 and then edge 3-4 or edge 2-3 and then edge 3-4)
Answer to the fourth question: [1] - [2] - [3] 1 [4] 0 [5] 1

Many thanks for your help!

_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help




--
Gabor Csardi <address@hidden>     MTA KFKI RMKI

reply via email to

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