dropUnusedLevels {Hmisc} | R Documentation |
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
level
s 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')
.
dropUnusedLevels()
Frank Harrell and Jens Oehlschlaegel
## 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)