简体   繁体   中英

iGraph in R - finding neighbors that meet a given edge score

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!

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#1在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM