[R] reduce levels

Claus Atzenbeck claus.atzenbeck at freenet.de
Tue Nov 8 18:10:02 CET 2005


On Tue, 8 Nov 2005 Bill.Venables at csiro.au wrote:

> sub$mm <- factor(sub$mm)

Great. This is exactly what I need.

> is the simplest way to change a single factor in this way.  To do a
> whole data frame you just need a loop:
>
> drop_unused_levels <- function(data)
> 	as.data.frame(lapply(data, function(x) if(is.factor(x))
> factor(x) else x ))

Thanks for this additional information. Maybe I'll be in need of it
later.

Greetings,
Claus




More information about the R-help mailing list