[R] removing NA as a level

Anne anne.piotet at urbanet.ch
Mon Dec 6 14:29:06 CET 2004


Thank you! so easy and I did not think of it!

----- Original Message ----- 
From: "Chuck Cleland" <ccleland at optonline.net>
To: "Anne" <anne.piotet at urbanet.ch>
Cc: "R list" <r-help at stat.math.ethz.ch>
Sent: Monday, December 06, 2004 2:12 PM
Subject: Re: [R] removing NA as a level


> dat$x.f <- factor(replace(dat$x.f, dat$x.f == "NA", NA))
>
> Anne wrote:
> > Dear R-helpers,
> > I have a problem which I suppose is trivila, but...
> > I have included NA values as factors ( (to be able to make nice printed
summaries with NAs % ba category ) with the following code
> >
> > dat$x.f<-factor(dat$x, exclude=NULL);
levels(dat$x.f)<-c("A1","A2","A3","A4","NA"); length(dat$x.f)
> >
> > Now, I want to impute the missing values. Is there a nice way to drop
the NA factor instead of rewriting something of the sort
> >  dat$x.f<-factor(dat$x); levels(dat$x.f)<-c("A1","A2","A3","A4");
length(dat$x.f)?
>
> -- 
> Chuck Cleland, Ph.D.
> NDRI, Inc.
> 71 West 23rd Street, 8th floor
> New York, NY 10010
> tel: (212) 845-4495 (Tu, Th)
> tel: (732) 452-1424 (M, W, F)
> fax: (917) 438-0894
>




More information about the R-help mailing list