rgraphigraphbipartiteedge-list

bipartite graph from edgelist with make_bipartite_graph() - Invalid vertex ID error


First post, so please be lenient...

problem: I am trying to use an edges-vector and types vector to use the iGraph function make_bipartite_graph() in R, however I run into an error concerning Vertex IDs:

Error - At core/misc/bipartite.c:527 : Invalid (negative or too large) vertex id, Invalid vertex id

#types in form of NodesAndType gives the boolean info for all 122 nodes
#whether they belong to nodeSet1 or nodeSet2

> head(NodesAndType[,2])
[1] FALSE FALSE FALSE FALSE FALSE FALSE

> length(NodesAndType[,2])
[1] 122

make_bipartite_graph(types = NodesAndType[,2], edges = EL_vector)

#**edges** in form of the EL_vector gives all edges of the graph in from-to format in one vector

> head(EL_vector)
[1]   1 201   2 201   3 201

> head(NodesAndType[,2])
[1] FALSE FALSE FALSE FALSE FALSE FALSE

> length(NodesAndType[,2])
[1] 122

make_bipartite_graph(types = NodesAndType[,2], edges = EL_vector)
## make_bipartite_graph is throwing thefollowing error

make_bipartite_graph(types = NodesAndType[,2], edges = EL_vector)

>Error in make_bipartite_graph(types = NodesAndType[, 2], edges = EL_vector) : 
> At core/misc/bipartite.c:527 : Invalid (negative or too large) vertex id, Invalid vertex id

# the two nodesets are
## nodeset1 (type FALSE for bipartite)
nodeset1 <- 1:103

## nodeset2 (type TRUE for bipartite)
nodeset2 <- 201:211

SessionInfo()

>R version 4.1.2 (2021-11-01)
>Platform: x86_64-w64-mingw32/x64 (64-bit)
>Running under: Windows 10 x64 (build 22000)

>Matrix products: default
>attached base packages:
>[1] stats     graphics  grDevices utils     datasets  methods   base     
>other attached packages:
[1] igraph_1.3.1 dplyr_1.0.7

Solution

  • With make_bipartite_graph, the vertices are defined by the types vector. The number of vertices is the same as the length of types. In your example, you have 122 vertices, but you are referring to vertex ID 201, which is invalid (too large).