-
Notifications
You must be signed in to change notification settings - Fork 7
Description
When called with a two-mode adjacency matrix, as.network.matrix will correctly interpret this as a graph with an enforced bipartition, with the passed matrix being the off-diagonal portion of the full adjacency matrix. as.network.data.frame will not, and indeed returns errors if e.g. the matrix is square and has non-zero diagonal entries when loops==FALSE. (See also related issue of as.network.data.frame not respecting the same semantics as as.network.matrix.) Setting loops=TRUE and bipartite=TRUE does not rectify the problem, because it throws an error when loops are set on bipartite graphs.
For this issue, the needed fix is for as.network.data.frame to correctly detect and implement two-mode matrix processing. Here is a demonstration:
#Create a two-mode adjacency structure
set.seed(1331)
g<-matrix(rbinom(25,1,0.2),5,5)
diag(g)<-1
#Coerce to a graph the traditional way
gn<-as.network.matrix(g,bipartite=T)
gn
gn[,]
#Now, with data frames.
gf<-as.data.frame(g)
gfn<-as.network(gf,bipartite=T) #Loop error!
gfn<-as.network(gf,bipartite=T,loops=T) #Displeased!
as.network.matrix(gf,bipartite=T) #Works fine!We should be seeing the same behavior for as.network.data.frame as as.network.matrix here, and are not.