s-news
[Top] [All Lists]

How to drop unused factor levels globally?

To: "'S-news'" <s-news@lists.biostat.wustl.edu>
Subject: How to drop unused factor levels globally?
From: "Byers, Bob" <rhb1@cdc.gov>
Date: Thu, 29 Nov 2001 09:05:00 -0500
Hi,
        Under S-plus 6 on Win2000:
        I'm removing rows from a data frame like this:
.drop<-X$ID=="C1234"
X<-X[!.drop,]

There are several factors in X and they all keep all
their original levels. I've tried to get rid of them by:

options(drop.unused.levels=T)

and

X<-X[!.drop,,drop=T]

but neither works. The best I can do is drop the 
levels a factor at a time:

library(Hmisc,T)
X$ID<-factor(X$ID)

OR

X$ID<-"[.factor"(X,,drop=T)

but that's boring.  Is there a way to get all the factors to
lose the superfluous levels automatically?
Thanks,
Bob Byers


Robert H. Byers, Jr. PhD
Statistics & Data Mgmt.
Div. of HIV-AIDS Prevention, CDC
bbyers@cdc.gov
(404) 639-2025

<Prev in Thread] Current Thread [Next in Thread>
  • How to drop unused factor levels globally?, Byers, Bob <=