Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

as.network.data.frame does not handle two-mode adjacency matrices correctly

Open
#64 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start by reproducing the two-mode example in the issue, then compare how as.network.data.frame and as.network.matrix interpret bipartite input. Trace the handling of bipartite and loops arguments in both entry points. Done means as.network.data.frame matches as.network.matrix without loop-related errors for the demonstrated input.

Written by the indexing model from the issue text.

Description

bug

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.

Dominant language
R
Stars
20
Forks
7
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from statnet/network

All issues in statnet/network

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.