[R] removing NA as a level
Petr Pikal
petr.pikal at precheza.cz
Mon Dec 6 14:31:59 CET 2004
On 6 Dec 2004 at 13:58, 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)?
Hi Anne
Is this
dat$x.f[!is.na(dat$x.f), drop=T]
what you want?
?"[.factor"
Cheers
Petr
>
> Thanks
>
> Anne
>
>
> ----------------------------------------------------
> Anne Piotet
> Tel: +41 79 359 83 32 (mobile)
> Email: anne.piotet at m-td.com
> ---------------------------------------------------
> M-TD Modelling and Technology Development
> PSE-C
> CH-1015 Lausanne
> Switzerland
> Tel: +41 21 693 83 98
> Fax: +41 21 646 41 33
> --------------------------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list