Hello all, I have a *.csv file that looks like this (actual file is orders of magnitude larger): Site taxa no.ind forest LMA 1 forest LCY 1 forest SCO 1 meadow LMA 2 meadow LCY 1 meadow PNT 3 I am interested in, but have failed to create, code that efficiently converts it to a site-by-taxa matrix or data frame that looks like this: LMA LCY SCO PNT Forest 1 1 1 0 Meadow 2 1 0 3 With no repeating taxa names and zeros where a taxon is not listed for a site. Any help would be greatly appreciated. Regards, Drew Garey Aquatic Ecoloy Lab Manager Virginia Commonwealth University [[alternative HTML version deleted]]
There are various ways, but for simple convenience that's exactly the job that crosstab() in ecodist was written for. Sarah On Sat, Feb 7, 2009 at 2:47 PM, Drew Garey <corydalus at gmail.com> wrote:> Hello all, > > > > I have a *.csv file that looks like this (actual file is orders of magnitude > larger): > > > > Site taxa no.ind > > forest LMA 1 > > forest LCY 1 > > forest SCO 1 > > meadow LMA 2 > > meadow LCY 1 > > meadow PNT 3 > > > > I am interested in, but have failed to create, code that efficiently > converts it to a site-by-taxa matrix or data frame that looks like this: > > > > LMA LCY SCO PNT > > Forest 1 1 1 0 > > Meadow 2 1 0 3 > > > > > > With no repeating taxa names and zeros where a taxon is not listed for a > site. Any help would be greatly appreciated. > > > > Regards, > > > > Drew Garey > > Aquatic Ecoloy Lab Manager > > Virginia Commonwealth University > > [[alternative HTML version deleted]] >-- Sarah Goslee http://www.functionaldiversity.org
on 02/07/2009 01:47 PM Drew Garey wrote:> Hello all, > > > > I have a *.csv file that looks like this (actual file is orders of magnitude > larger): > > > > Site taxa no.ind > > forest LMA 1 > > forest LCY 1 > > forest SCO 1 > > meadow LMA 2 > > meadow LCY 1 > > meadow PNT 3 > > > > I am interested in, but have failed to create, code that efficiently > converts it to a site-by-taxa matrix or data frame that looks like this: > > > > LMA LCY SCO PNT > > Forest 1 1 1 0 > > Meadow 2 1 0 3 > > > > > > With no repeating taxa names and zeros where a taxon is not listed for a > site. Any help would be greatly appreciated.See ?xtabs If your data is in a data frame called 'DF':> DFSite taxa no.ind 1 forest LMA 1 2 forest LCY 1 3 forest SCO 1 4 meadow LMA 2 5 meadow LCY 1 6 meadow PNT 3> xtabs(no.ind ~ Site + taxa, data = DF)taxa Site LCY LMA PNT SCO forest 1 1 0 1 meadow 1 2 3 0 HTH, Marc Schwartz
Drew, would look at the reshape package On Sat, Feb 7, 2009 at 2:47 PM, Drew Garey <corydalus@gmail.com> wrote:> Hello all, > > > > I have a *.csv file that looks like this (actual file is orders of > magnitude > larger): > > > > Site taxa no.ind > > forest LMA 1 > > forest LCY 1 > > forest SCO 1 > > meadow LMA 2 > > meadow LCY 1 > > meadow PNT 3 > > > > I am interested in, but have failed to create, code that efficiently > converts it to a site-by-taxa matrix or data frame that looks like this: > > > > LMA LCY SCO PNT > > Forest 1 1 1 0 > > Meadow 2 1 0 3 > > > > > > With no repeating taxa names and zeros where a taxon is not listed for a > site. Any help would be greatly appreciated. > > > > Regards, > > > > Drew Garey > > Aquatic Ecoloy Lab Manager > > Virginia Commonwealth University > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]