For example, I have a data frame looks like this, the 'species' column (total 8 species) represent species name, the 'site' column (total 4 sites) represent which site each species appearance
Example input:
# species site
#1 sp1 1
#2 sp2 1
#3 sp3 1
#4 sp4 2
#5 sp5 2
#6 sp1 2
#7 sp2 2
#8 sp6 3
#9 sp1 3
#10 sp2 3
#11 sp7 4
#12 sp8 4
#13 sp6 4
Desired output:
#site sp1 sp2 sp3 sp4 sp5 sp6 sp7 sp8
#1 1 1 1 0 0 0 0 0
#2 1 1 0 1 1 0 0 0
#3 1 1 0 0 0 1 0 0
#4 0 0 0 0 0 1 1 1
How can I transfer this data frame into a data matrix, where rownames are sites name (i.e., 1 2 3 4) and column names are species name? And I want the final output to be a data matrix.