Apologies in advance, I had a hard time titling this question. I have a species interaction matrix where the columns and rows represent species, and the matrix fill is the frequency of their interactions:
matrix<- 2A 2B 2C
1A 1 2 4
1B 0 1 1
1C 5 4 1
I want to make a matrix with the following form:
mat<-
comm
1A_2A 1
1A_2B 2
1A_2C 4
1B_2A 0
1B_2B 1
1B_2C 1
1C_2A 5
1C_2B 4
1C_2C 1
where the species interaction becomes the rows and the column can be any variable, but the matrix fill remains the frequency of interactions and the structure remains a matrix. This way the matrix takes the form of a community x species matrix. The reason I want to collapse the matrix in this way and retain matrix form is to enable use of functions in library(vegetarian)
such as d()
which requires a matrix form.