我有一个物种间的相互作用网络,第一行是捕食者身份,第一列是猎物身份。矩阵用 0 或 1 填充,表示存在或不存在交互。我想将此矩阵转换为具有两列的数据框,第一列包含捕食者的身份,第二列包含猎物的身份。因此,每一行将由不同的捕食者-猎物组合定义,代表一种独特的相互作用。这是它的样子:
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
非常感谢
瓦莱丽