-1

I'm trying to analyse a bipartite network using the R bipartite package. I imported a csv file and converted it to a one mode network. Here's my code:

library(igraph) 
library(bipartite) 
g <- as.network(data)  
net <- as.one.mode(g, fill = 0, project="full", weighted=TRUE) 
summary(net) 
vcount(net) 
ecount(net)  

But, when I try to calculate network metrics using the following command, it gives me an error.

betweenness_w(net, directed=NULL, alpha=1)

Here's the error message.

Error in if (NC == 2) net <- data.frame(tmp[, 1], tmp[, 2]) : 
  argument is of length zero

I appreciate some help

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Chamil
  • 1
  • 1
  • 2
    It would be easier to help if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data – MrFlick May 08 '17 at 21:44

1 Answers1

0

You could be confusing igraph graph objects with matrices.

For example I can replicate your error by feeding a graph object to the betweeness_w function:

> g=make_full_graph(5)
> ecount(g)
[1] 10
> betweenness_w(g)
Error in if (NC == 2) net <- data.frame(tmp[, 1], tmp[, 2]) : 
  argument is of length zero

But betweenness_w wants a weighted edge list. See the documentation.

Of course this is speculation because you've not given us a reproducible example.

Spacedman
  • 92,590
  • 12
  • 140
  • 224
  • Thanks very much. This is very helpful. Could you tell me how to create a weighted edgelist from a csv file that has two columns (representing the two types of nodes)? – Chamil May 08 '17 at 22:30
  • you should edit your question to clarify thats what you are trying to do, and include a sample of your CSV file and any other data. If you can't edit this question, start a new one. – Spacedman May 09 '17 at 06:29