R中的iGraph - 找到满足给定边缘得分的邻居

时间:2013-11-20 03:16:25

标签: r igraph

有没有办法在邻域函数中应用限制:

http://igraph.sourceforge.net/doc/R/neighborhood.html

仅获取通过给定边缘阈值连接的邻居?例如:

  1. 如果我想要边缘权重> = 0.5
  2. 的第一阶邻居
  3. 我希望第二顺序中与第一跳边缘权重相关的所有邻居== 1和第二跳边缘权重== 1
  4. 谢谢!

1 个答案:

答案 0 :(得分:1)

如果我理解正确,那么您可以做的就是限制权重的原始图表的子集。

> 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 enter image description here