I have a dataframe (in the form of an excel file) with rows of sampled sites and columns of each species (sp). A very standard community ecology species by sites matrix but in dataframe format.
example data (note i added a column for site names as that's how it is in my excel file):
sites<-c("SiteA", "SiteB", "SiteC")
sp1<-c(0, 5, 2)
sp2<-c(0, 1, 2)
sp3<-c(1, 1, 4)
comm<-data.frame(sites,sp1,sp2,sp3)
In my situation I only have one of these dataframes or one "plot". I need to convert this dataframe into a matrix formatted like below:
sp site plot Abundance
1 sp1 A 1 0
2 sp2 A 1 0
3 sp3 A 1 1
4 sp1 B 1 5
5 sp2 B 1 5
6 sp3 B 1 1
7 sp1 C 1 2
8 sp2 C 1 2
9 sp3 C 1 4
I have looked into using techniques described in this previous post (Collapse species matrix to site by species matrix) but the end result is different from mines where I need my matrix to ultimately look like what I showed above.
Any help would be greatly appreciated.