Re: [Rd] R 2.5.1 - ?factor examples, details

From: Peter Dalgaard <>
Date: Tue, 03 Jul 2007 09:08:46 +0200

François Pinard wrote:
> Hi, R people.
> In ?factor, in the "Examples:" section, we see:
> ## suppose you want "NA" as a level, and to allowing missing values.
> (x <- factor(c(1, 2, "NA"), exclude = ""))
>[2] <- TRUE
> x # [1] 1 <NA> NA, <NA> used because NA is a level.
> I'm a bit confused by this example, as I do not understand the point
> being made. Using 'exclude = ""' or not does not change the outcome.
> What is being demonstrated by this clause, here? Isn't "NA" a mere
> string, not really related to a missing value?
> It might also be some kind of linguistic problem, and I'm not a native
> English speaker. The "and to allowing" construct sounds strange to me.
> I would expect either "and to allow" or "and allowing", but maybe I'm
> plainly missing the meaning of the statement.
> Could this be clarified somehow?
I think this is a relic. In the olden days, there was no such thing as a missing character values, and factor() would behave like

 > (x <- factor(c(1, 2, "NA"), exclude = "NA")) [1] 1 2 <NA>
Levels: 1 2

...which was a pain when dealing with abbreviations for "noradrenalin", "North America", "New Alliance", "Neil Armstrong", etc. So character NA was added to R, and the example became irrelevant without anyone noticing. mailing list Received on Tue 03 Jul 2007 - 07:12:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jul 2007 - 09:35:52 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.