[R] Refactor all factors in a data frame

Gregor Gorjanc gregor.gorjanc at bfro.uni-lj.si
Wed Jun 6 12:12:49 CEST 2007


Hilmar Berger <hilmar.berger <at> imise.uni-leipzig.de> writes:
...
> So, is there any way in drop the unused factor levels from *all* factors 
> of a data frame without import/export ?

There is a generic drop.levels in gdata. Here is part of its help page:

"\code{drop.levels} is a generic function, where default method does
nothing, while method for factor \code{s} drops all unused levels.
There are also convenient methods for \code{list} and \code{data.frame},
where all unused levels are dropped in all factors (one by one) in a
\code{list} or a \code{data.frame}."

Gregor



More information about the R-help mailing list