Hmisc (version 3.0-12)

dropUnusedLevels: Create Temporary Factor Subsetting Function

Description

Calling this function makes Hmisc have its pre-version 3.0 behavior in which the R[.factor function was overridden by a customized version that caused unused factor levels to be dropped when the factor variable was subscripted (subsetted). dropUnusedLevels() creates a temporary version of [.factor in the global environment, which will take precedence. To later make this function keep unused levels on subsetting, issue options(drop.unused.levels=FALSE) or just remove this temporary function from the environment by issuing remove('[.factor',pos='.GlobalEnv').

Usage

dropUnusedLevels()

Arguments

See Also

factor,[.factor

Examples

Run this code
x <- factor(c('a','b','c'))
x[1:2]  # keeps level c
dropUnusedLevels()
x[1:2]  # no c any more

Run the code above in your browser using DataLab