#Produce some random data, and transform it
g<-rgraph(5)
g
all(g==as.sociomatrix.sna(g)) #TRUE
as.edgelist.sna(g) #View in edgelist form
as.edgelist.sna(list(g,g)) #Double the fun
g2<-as.sociomatrix.sna(list(g,g)) #Will simplify to an array
dim(g2)
g3<-as.sociomatrix.sna(list(g,g),simplify=FALSE) #Do not simplify
g3 #Now a list
#We can also build edgelists from scratch...
n<-6
edges<-rbind(
c(1,2,1),
c(2,1,2),
c(1,3,1),
c(1,5,2),
c(4,5,1),
c(5,4,1)
)
attr(edges,"n")<-n
attr(edges,"vnames")<-letters[1:n]
gplot(edges,displaylabels=TRUE) #Plot the graph
as.sociomatrix.sna(edges) #Show in matrix form
#Two-mode data works similarly
n<-6
edges<-rbind(
c(1,4,1),
c(1,5,2),
c(4,1,1),
c(5,1,2),
c(2,5,1),
c(5,2,1),
c(3,5,1),
c(3,6,2),
c(6,3,2)
)
attr(edges,"n")<-n
attr(edges,"vnames")<-c(letters[1:3],LETTERS[4:6])
attr(edges,"bipartite")<-3
edges
gplot(edges,displaylabels=TRUE,gmode="twomode") #Plot
as.sociomatrix.sna(edges) #Convert to matrix
Run the code above in your browser using DataLab