Bug 16348 - Label of NA values in summary.factor
Summary: Label of NA values in summary.factor
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: R 3.2.0
Hardware: Other Other
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2015-04-28 17:27 UTC by Thomas J. Leeper
Modified: 2016-02-07 16:00 UTC (History)
2 users (show)

See Also:

fix for the question (1.05 KB, patch)
2016-02-07 16:00 UTC, Amur Ghose
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas J. Leeper 2015-04-28 17:27:34 UTC
This is a grammatical suggestion related to `summary.factor()`. The current output of `summary.factor()`, when the input vector has NA values, includes a count of NA values labeled "NA's":

> summary(factor(c(1,2,NA)))
   1    2 NA's 
   1    1    1 

According to the Oxford English Dictionary <http://www.oxforddictionaries.com/words/apostrophe>, an apostrophe should only be used to clarify meaning when attempting to pluralise a letter (e.g., "p's") or a number (e.g., "7's"). So, this should really be "NAs" not "NA's". I might suggest, however, that it instead be changed to "<NA>", so that the output is consistent with `table()`:

> table(factor(c(1,2,NA)), useNA="always")
   1    2 <NA> 
   1    1    1 

The relevant code is the last three lines of `summary.factor()`:

if (any(nas)) 
    c(tt, `NA's` = sum(nas))
else tt

which could be changed to:

if (any(nas)) 
    c(tt, `<NA>` = sum(nas))
else tt

This would also help to distinguish the results more clearly from a factor level labeled (perhaps erroneously) "NA":

> summary(factor(c("NA",NA)))
  NA NA's 
   1    1


> table(factor(c("NA",NA)), useNA="always")
  NA <NA> 
   1    1
Comment 1 Thomas J. Leeper 2015-04-28 17:34:27 UTC
The same usage occurs in `summary.default()` for numeric vectors (code is identical to `summary.factor()`) and for logical vectors (though the code in the latter case is slightly different).
Comment 2 Amur Ghose 2016-02-07 16:00:09 UTC
Created attachment 2020 [details]
fix for the question

Seems pedantic but you can try this ( not much change, just changed NA's to <NA> )

On the other hand , the make check failed when I ran on it on my own PC. I'll look up more on the dependency of the summary functions.