簡體   English   中英

R和igraph:基於入射在邊緣的其他節點的屬性的子圖節點

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM