[R] removing NA as a level
Chuck Cleland
ccleland at optonline.net
Mon Dec 6 14:12:43 CET 2004
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