[R-sig-eco] removing singleton taxa

Chris Howden chris at trickysolutions.com.au
Tue Dec 18 01:43:48 CET 2012


I'm not sure if I've got the syntax quite right ((m about to rush out the
door), but how about something like.

check <- colSums(df1>0)  ~ gives U a vector of the number of sites with
abundance > 0 for each species
check2 <- [check>1]          ~ gives U a logical vector which is FALSE  if
a species occurs in 0 or 1 site, TRUE otherwise

df2 <- df1[,check2]            ~ subset those columns that are TRUE i.e.
have a species in more than 1 site.



Chris Howden B.Sc. (Hons) GStat.
Founding Partner
Evidence Based Strategic Development, IP Commercialisation and Innovation,
Data Analysis, Modelling and Training
(mobile) 0410 689 945
(fax) +612 4782 9023
chris at trickysolutions.com.au




Disclaimer: The information in this email and any attachments to it are
confidential and may contain legally privileged information. If you are
not the named or intended recipient, please delete this communication and
contact us immediately. Please note you are not authorised to copy, use or
disclose this communication or any attachments without our consent.
Although this email has been checked by anti-virus software, there is a
risk that email messages may be corrupted or infected by viruses or other
interferences. No responsibility is accepted for such interference. Unless
expressly stated, the views of the writer are not those of the company.
Tricky Solutions always does our best to provide accurate forecasts and
analyses based on the data supplied, however it is possible that some
important predictors were not included in the data sent to us. Information
provided by us should not be solely relied upon when making decisions and
clients should use their own judgement.


-----Original Message-----
From: r-sig-ecology-bounces at r-project.org
[mailto:r-sig-ecology-bounces at r-project.org] On Behalf Of Kate Boersma
Sent: Tuesday, 18 December 2012 11:23 AM
To: r-sig-ecology at r-project.org
Subject: [R-sig-eco] removing singleton taxa

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

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



More information about the R-sig-ecology mailing list