#Create an arbitrary adjacency matrix
m<-matrix(rbinom(25,1,0.5),5,5)
diag(m)<-0
g<-network.initialize(5) #Initialize the network
network.adjacency(m,g) #Import the edge data
#Do the same thing, using replacement operators
g<-network.initialize(5)
g[,]<-m
# load edges from a data.frame via network.edgelist
edata <-data.frame(
tails=c(1,2,3),
heads=c(2,3,1),
love=c('yes','no','maybe'),
hate=c(3,-5,2),
stringsAsFactors=FALSE
)
g<-network.edgelist(edata,network.initialize(4),ignore.eval=FALSE)
as.sociomatrix(g,attrname='hate')
g%e%'love'
# load edges from an incidence matrix
inci<-matrix(c(1,1,0,0, 0,1,1,0, 1,0,1,0),ncol=3,byrow=FALSE)
inci
g<-network.incidence(inci,network.initialize(4,directed=FALSE))
as.matrix(g)
Run the code above in your browser using DataLab