|
From: | Marie Lalanne |
Subject: | Re: [igraph] degrees of separation |
Date: | Mon, 24 Jun 2013 12:23:58 +0100 (BST) |
Hi Gabor,many thanks for your quick answer.When I write one of the command with "g[a,b]", R is telling me that the dimension is not correct. I guess this is due to the graph object (which is a list of edges so R understands one dimension, maybe?)
The command "shortest.paths" cannot have as argument "to=1" so I have found the following way to compute the shortest path:
c<-get.all.shortest.paths(g, v, to=s)d<-lapply(c, length)min(unlist(d))
I did a mistake in my first question: in my example, the number of vertices connected to s would be 3 but I would like to get the number 2 instead (because I want to count 1 for the link 2-5 and 1 for the links 1-3 and 2-3).
Many thanks again for all your help!Very best,Marie
De : Gábor Csárdi <address@hidden>
À : Marie Lalanne <address@hidden>; Help for igraph users <address@hidden>
Envoyé le : Mardi 21 mai 2013 18h57
Objet : Re: [igraph] degrees of separation
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 21 32 32 53 43 54 5"g <- graph.data.frame(read.table(textConnection(data)),directed=FALSE, vertices=data.frame(1:5))s <- c(1,2)v <- 4I 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 subsetcolSums(g[s,]) != 0Please see the manual, in particular ?'[.igraph' for details.Best,Gaborps. be critical with my answers, and check them, I haven't checked them too extensively.For example:1-21-32-32-53-43-54-5and consider the subset of vertices being 1 and 2 and the particular vertex being 4Answer 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] 1Many 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
[Prev in Thread] | Current Thread | [Next in Thread] |