Reputation: 610
Is there a way to apply a restriction in the neighborhood function:
http://igraph.sourceforge.net/doc/R/neighborhood.html
To only get neighbors that are connected by a given edge threshold? So for example:
Thanks!
Upvotes: 2
Views: 1676
Reputation: 20045
If I understand you correctly then what you could do is subset the original graph restricting the weights.
> library(igraph)
> df <- data.frame(
a = c("n1","n1","n1","n1","n2"),
b = c("n2","n3","n4","n5","n3"),
w = c(-1,1,-1,1,-1))
> g <- graph.data.frame(df, directed=FALSE)
> plot(g, edge.label=E(g)$w)
[img #1]
# restrict graph to edges with value w being negative
> subg <- graph.neighborhood(
subgraph.edges(g, eids = which(E(g)$w < 0)),
order = 1)
> subg
[[1]]
IGRAPH UN-- 3 2 --
+ attr: name (v/c), w (e/n)
[[2]]
IGRAPH UN-- 3 2 --
+ attr: name (v/c), w (e/n)
[[3]]
IGRAPH UN-- 2 1 --
+ attr: name (v/c), w (e/n)
[[4]]
IGRAPH UN-- 2 1 --
+ attr: name (v/c), w (e/n)
> plot(subg[[1]], edge.label=E(subg[[1]])$w)
[img #2]
Upvotes: 1