Drop Levels of a Factor that Never Occur
Reform a factor so that only necessary levels are kept.
dropEmptyLevels(x)
x |
a factor or a vector to be converted to a factor. |
In general, the levels of a factor, levels(x)
, may include values that never actually occur.
This function drops any levels of that do not occur.
If x
is not a factor, then the function returns factor(x)
.
If x
is a factor, then the function returns the same value as factor(x)
or x[,drop=TRUE]
but somewhat more efficiently.
A factor with the same values as x
but with a possibly reduced set of levels.
Gordon Smyth
x <- factor(c("a","b"), levels=c("c","b","a")) x dropEmptyLevels(x)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.