2
votes

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:

  1. If I want 1st order neighbors with edge weight >= 0.5
  2. I want all neighbors within second order that are connected with first hop edge weight == 1 and 2nd hop edge weight == 1

Thanks!

1

1 Answers

1
votes

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]

img #1enter image description here