This might be a very straight forward question, but I seem not to be able to work it out.
In R I have a network object of 251739 nodes (inventors) and 759804 edges (collaborations on patents). Both nodes and edges have attribute files. One of such a edge attribute is appyear
, i.e. the year the inventors applied for a patent.
I want to write all nodes that are incidence on a patent for which appyear == 2005
to a new network.
Can someone give me some pointer on how to do this? I use the latest version of R and the STATNET package.
So here's a method using the igraph
package.
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
uses objects of class network
, so we convert at the end.
library(network)
new.network <- as.network(get.edgelist(new.g))