I want to turn a matrix into a long data.frame edge list of rows to columns like this:
set.seed(666)
mat <- matrix(sample(0:1,12,replace=TRUE),nrow=3)
library(bipartite)
as.data.frame(web2edges(mat, return = TRUE))
but i want names of the rows and columns to be in the output for the row
and col
columns not the number of the row.
but when i try this i get a duplicate row name error:
set.seed(666)
mat <- matrix(sample(0:1,12,replace=TRUE),nrow=3)
colnames(mat) <- letters[1:4]
rownames(mat) <- letters[5:7]
library(bipartite)
as.data.frame(web2edges(mat, return = TRUE))
Error in data.frame(row = c("1", "3", "3", "1", "2"), col = c("4", "4", : duplicate row.names: g, e
Is there another easy way this can be achieved without using web2edges
?