0

I have an Excel table (.csv), like this (with duplicate species):

Species     Site 
Panthera    A 
Panthera    B 
Panthera    C 
Neofelis    B 
Neofelis    D

and I would like to use R to create a presence-absence matrix, like this:

Site    Panthera    Neofelis
A          1           0
B          1           1
C          1           0
D          0           1

How I could do it, please? Thanks!

M.S.
  • 37
  • 1
  • 5

1 Answers1

4

We can use dcast

library(reshape2)
dcast(df1, Site~Species, length)
akrun
  • 874,273
  • 37
  • 540
  • 662