[R] data transformation

Christian Hof chof at bio.ku.dk
Tue Jul 22 18:24:46 CEST 2008


Dear all,

how can I, with R, transform a presence-only table (with the names of 
the species (1st column), the lat information of the sites (2nd column) 
and the lon information of the sites (3rd column)) into a 
presence-absence (0/1) matrix of species occurrences across sites, as 
given in the below example?

Thanks a lot for your help!
Christian



My initial table:

species	lat	lon
sp1	10	10
sp1	10	30
sp1	20	10
sp1	20	20
sp1	20	30
sp2	10	30
sp2	20	30
sp2	30	30


My desired matrix:

lat	lon	sp1	sp2
10	10	1	0
10	20	0	0
10	30	1	1
20	10	1	0
20	20	1	0
20	30	1	1
30	10	0	0
30	20	0	0
30	30	0	1


-- 
Christian Hof, PhD student

Center for Macroecology & Evolution
University of Copenhagen
www.macroecology.ku.dk
&
Biodiversity & Global Change Lab
Museo Nacional de Ciencias Naturales, Madrid
www.biochange-lab.eu

mobile ES .. +34 697 508 519
mobile DE .. +49 176 205 189 27
       mail .. chof at bio.ku.dk
      mail2 .. vogelwart at gmx.de
       blog .. www.vogelwart.de



More information about the R-help mailing list