I have a species by species interaction network, with predator identity in the first row and prey identity in the first column. The matrix is filles with 0 or 1 representing the presence or absence of an interaction. I would like to convert this matrix into a dataframe with two columns, the first column containing the identity of the predator and the second the identity of the prey. Thus each row would be defined by a different predator-prey combinaison, representing a unique interaction. Here is how it should look like:
int.matrix <- matrix(c(1,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0),nrow=4,ncol=4)
rownames(int.matrix)<-c("prey1","prey2","prey3","prey4")
colnames(int.matrix)<-c("pred1","pred2","pred3","pred4")
int.matrix
pred1 pred2 pred3 pred4
prey1 1 0 1 0
prey2 1 1 0 1
prey3 0 0 0 0
prey4 1 0 1 0
L1 <- c("pred1","pred1","pred1","pred2","pred3","pred3","pred4")
L2 <- c("prey1","prey2","prey4","prey2","prey1","prey4","prey2")
data.frame(cbind(L1,L2))
L1 L2
1 pred1 prey1
2 pred1 prey2
3 pred1 prey4
4 pred2 prey2
5 pred3 prey1
6 pred3 prey4
7 pred4 prey2
Thank you very much
Valerie