dropUnusedLevels {Hmisc}R Documentation

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()

Author(s)

Frank Harrell and Jens Oehlschlaegel

See Also

factor,[.factor

Examples

## Not run: 
x <- factor(c('a','b','c'))
x[1:2]  # keeps level c
dropUnusedLevels()
x[1:2]  # no c any more
## End(Not run)

[Package Hmisc version 3.0-10 Index]