Ghost Factor Levels in R

Possible duplicate:
reduction factor levels in a subset of data in R

I have a subset of observations with a certain level of factor. Checking if this was done with summary(), the levels were still listed, but with zero observations. Do they not disappear during a subset?

+5
source share
2 answers

The subset does not leave empty levels. Why this is so is that it is a feature. Think about it as your factor levels determine the possible / potential categories. If you take only a subset of these things, the possible categories of a thing do not change; your subset simply does not contain them.

, . ?droplevels.

+14

, drop=TRUE, :

newfactor <- oldfactor[indices, drop=TRUE]

, , , . , , , , .

+8

All Articles