[Rd] Dropping unused levels of a factor that has "NA" as a level

From: J. Hosking <jh910_at_juno.com>
Date: Tue 11 Jul 2006 - 20:52:04 GMT


Is this a bug?

> f1 <- factor(c("a", NA), levels = c("a", "NA") )
> f2 <- f1[, drop = TRUE]
> f2

   [1] a <NA>
   Levels: a <NA>

I would have expected f2 to have only one level, "a". It seems to me that the code in [.factor does not follow the advice in help("factor") on how to set factor codes to be missing when "NA" is a level of the factor.

J. R. M. Hosking



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed Jul 12 06:58:01 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 11 Jul 2006 - 22:28:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.