yiwu ye <yiwu21111958 <at> yahoo.com> writes:
> Dear list,I have the following problem. Could anyone
help?x_as.factor(letters[1:5])x_x[-4]levels(x)The levels(x) still gives you 5
rather than 4 levels. Of course, I can do levels(as.factor(as.character(x)) to
get rid of the non-existing factor level. But, I think there must be a simpler
way.ThanksYiwu
Not sure about S-plus, but in R you can simply do
myFac <- factor(myFac)
and unused levels will be dropped. Package gdata has drop.levels function,
which
also works on data.frames. I use it in my work flow like this:
1. import data
2. massage it if neccesarry
3. use drop.levels at the end and it will remove all unused levels in a
data.frame
Gregor
|