igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] getting k-connected nodes from a vertex


From: Tamas Nepusz
Subject: Re: [igraph] getting k-connected nodes from a vertex
Date: Thu, 06 Dec 2012 11:48:22 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

> Thanks Tamas Nepusz. Following your suggestions let me proceed to get 2
> levels of nearest neighbor. In fact I don't quite get the usage of [[]] and
> the "1" inside the bracket (first element in an array?), and it's difficult
> to google by using [[]], would you please refer me for further reference?
graph.neighborhood returns a list of graphs, one for each vertex that you
specify. E.g., you could do this:

graph.neighborhood(g, 1, c("A", "B", "C"))

This would give you three graphs, one centered on "A", one centered on "B"
and one centered on "C". This would be returned in a list with three
elements. Since you specified only "A" for graph.neighborhood, it will
return a list of one element only, but you still need to refer to the first
element with [[1]] to get the actual graph.

> Moreover, do you know why graph.neighborhood(g, 1, "A") return up to the 2nd
> level?
What makes you think that? graph.neighborhood will return the vertex and its
first-order neighbors only:

> g <- graph.famous("petersen")
> V(g)$name <- LETTERS[1:10]
> g2 <- graph.neighborhood(g, 1, "A")[[1]]
> V(g2)$name
[1] "A" "B" "E" "F"
> V(g)$name[neighbors(g, "A")]
[1] "B" "E" "F"

The only thing you have to watch out for is that if your graph is directed,
you have to specify whether you need the out-neighborhood (by adding
mode="out" to the parameters of graph.neighborhood), the in-neighborhood (by
adding mode="in") or both (by adding mode="all" or by not adding anything)

-- 
T.



reply via email to

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