Learn R Programming

base (version 3.0.3)

droplevels: droplevels

Description

The function droplevels is used to drop unused levels from a factor or, more commonly, from factors in a data frame.

Usage

"droplevels"(x, ...) "droplevels"(x, except, ...)

Arguments

x
an object from which to drop unused factor levels.
...
further arguments passed to methods
except
indices of columns from which not to drop levels

Value

droplevels returns an object of the same class as x

Details

The method for class "factor" is essentially equivalent to factor(x).

The except argument follow the usual indexing rules.

See Also

subset for subsetting data frames. factor for definition of factors. drop for dropping array dimensions. drop1 for dropping terms from a model. [.factor for subsetting of factors.

Examples

Run this code
aq <- transform(airquality, Month = factor(Month, labels = month.abb[5:9]))
aq <- subset(aq, Month != "Jul")
table(aq$Month)
table(droplevels(aq)$Month)

Run the code above in your browser using DataLab