How can I create a binary matrix from a data.frame with two columns where the first column represents e.g. species and the other their region? The data.frame is in tall format as seen below
species region
species1 1
species1 2
species1 3
species2 2
species2 4
species2 5
species2 6
species3 1
species3 2
species4 5
species5 3
species5 4
And the matrix would have all unique species as rows and all unique regions as columns. The matrix would be filled with 1s for species present and 0s for species absent, as below
1 2 3 4 5 6
species1 1 1 1 0 0 0
species2 0 1 0 1 1 1
species3 1 1 0 0 0 0
species4 0 0 0 0 1 0
species5 0 0 1 1 0 0
Any pointers would be very much appreciated, thanks!