这可能是一个非常直接的问题,但我似乎无法解决。
在 R 中,我有一个包含 251739 个节点(发明者)和 759804 个边(专利合作)的网络对象。节点和边都有属性文件。这样的边缘属性之一是appyear
,即发明人申请专利的年份。
我想将与 appyear == 2005
的专利相关的所有节点写入新网络。
有人可以给我一些关于如何做到这一点的指示吗?我使用最新版本的 R 和 STATNET 包。
最佳答案
这里有一个使用 igraph
包的方法。
library(igraph)
# create an igraph with 25 authors; you have this already...
set.seed(1)
m <- matrix(sample(0:1,625,replace=T),nc=25)
diag(m) <- 0 # authors don't collaborate with themselves
g <- graph.adjacency(m,weight=T) # create the graph
E(g)$appyear <- sample(2000:2015,ecount(g),replace=T) # create an edge attribute "appyear"
# you start here...
g.new <- subgraph.edges(g,eids=which(E(g)$appyear==2005))
par(mfrow=c(1,2))
plot(g)
plot(g.new)
statnet
使用 network
类的对象,因此我们在最后进行转换。
library(network)
new.network <- as.network(get.edgelist(new.g))
关于r - 如何根据边缘值选择网络对象中的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24167514/