![](/img/trans.png)
[英]r igraph - Identify ties of nodes to a subgraph regardless of affiliation to said subgraph
[英]R and igraph: subgraph nodes based on attributes of other nodes that are incident on edge
我有专利发明人的合作数据。 每个发明人都是一个节点,每个边缘代表两个发明者合作的专利。 一些专利有> 2个发明人,因此一些专利用多个边缘表示。
我想要了解至少有一位发明家位于博伊西的专利,但并非所有发明家都位于博伊西。 其他专利和发明人需要从选择中排除。
例如:
gg <- graph.atlas(711)
V(gg)$name <- 1:7
V(gg)$city <- c("BOISE","NEW YORK","NEW YORK","BOISE","BOISE","LA","LA")
V(gg)$color <- ifelse(V(gg)$city=="BOISE", "orange","yellow")
gg<-delete.edges(gg, E(gg, P=c(1,2,2,3,2,7,7,6,7,3,3,4,3,5,4,5,5,6,6,1)))
gg <- add.edges(gg,c(1,4,4,5,5,1),attr=list(patent=1))
gg <- add.edges(gg,c(7,5,5,4,4,7),attr=list(patent=2))
gg <- add.edges(gg,c(7,3,3,5,5,7),attr=list(patent=3))
gg <- add.edges(gg,c(2,7,7,6,6,2),attr=list(patent=4))
gg <- add.edges(gg,c(6,4),attr=list(patent=5))
plot(gg, edge.label=E(gg)$patent)
生产:
网络示例http://i60.tinypic.com/34teolg.png
在这个网络中,我只想要将所有入射在专利2,3,5边缘的节点子图。
在此示例中,节点1不应该在子图中结束。 此外,还应排除从专利#1的节点5到节点4的边缘。
我一直在努力解决这个问题。 这可能吗?
这个怎么样
#final all patent names
patents <- unique(edge.attributes(gg)$patent)
#check if criteria are met for patent
okpatents <- sapply(patents, function(p){
cities <- V(gg)[inc(E(gg)[patent==p])]$city
nc <- sum(cities=="BOISE")
return(nc>0 & nc < length(cities))
})
#extract subgraph
gs <- subgraph.edges(gg, E(gg)[patent %in% patents[okpatents]])
#verify
plot(gs, edge.label=E(gs)$patent)
PS。 非常好的可重复的例子;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.