[R] Bug in levels() function?

hadley wickham h.wickham at gmail.com
Mon Jan 28 14:22:56 CET 2008


> And subsetting a factor retains the original factor levels. To drop
> unused levels, just use factor(f[index]) or f[index, drop=TRUE]. The
> opposite behaviour can be even more annoying/dangerous because it leads
> to empty cells dropping out of tables and bars disappearing from barplots.

Of course you can apply the same reasoning to continuous variables
too.  I've always thought it would be interesting to have a continuous
analogue of a factor that preserved its original range by default.

Hadley


-- 
http://had.co.nz/



More information about the R-help mailing list