[R] dropping factor levels in subset

Nick Bond Nick.Bond at sci.monash.edu.au
Fri Jun 27 05:08:16 CEST 2003


Dear all,
I've taken a subset of data from a data frame using

crb<-subset(all.raw, creek %in% c("CR") & year %in% c(2000,2001) & substrate
%in% ("b"))

this works fine, except that all of the original factor levels are
maintained. This results in NA's for these empty levels when I try to do
summaries based on factors using by(). Is there a simple way to drop the
factor levels that are no longer represented. I've used na.omit on the
results from by, but then I have to deal with the attr setting, which
catches me too. Probably a silly question, but I've done a search and
couldn't find anything.  Can someone help me please.
Regards
Nick

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dr Nick Bond
Department of Biological Sciences
Monash University (Clayton Campus)
Victoria, Australia, 3800
Ph: +61 3 9905 5606 Fax: +61 3 9905 5613
Email: Nick.Bond at sci.monash.edu.au
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




More information about the R-help mailing list