[R-sig-eco] removing singleton taxa

Kate Boersma kate.boersma at science.oregonstate.edu
Tue Dec 18 01:22:41 CET 2012


Hi list. I am new to R and stuck on a very simple problem. Forgive me if 
this is not the right forum for my question - feel free to refer me 
elsewhere.

I have a community matrix of sites*species, and I want to remove species 
that only occur in a single site (singleton taxa). It sounds so simple, 
but I have spent hours (no joke) with google and my reference books and 
am still stuck.

Here's some example code:
Species1 = sample(0:20, 10, replace=TRUE)
Species2 = sample(0:20, 10, replace=TRUE)
Species3 = c(0,0,0,0,0,0,0,4,0,0)
df1 = data.frame(Species1, Species2, Species3)
df1

I want to remove Species 3. Basically, I want R to count the number of 
non-zero cells in a column and remove the column if that number is 1 or 0.

I have tried messing around with rowsums(), length(), table() and 
specnumber() in the vegan package and can't figure it out.

Thanks,
Kate

-- 
Kate Boersma
PhD Candidate
Oregon State University
Department of Zoology
Cordley 3029
Corvallis, OR 97331
kate.boersma at science.oregonstate.edu



More information about the R-sig-ecology mailing list