Bug 16750 - Treat character as factor in summary.default
Summary: Treat character as factor in summary.default
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-03-06 10:18 UTC by Thomas J. Leeper
Modified: 2016-03-06 10:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas J. Leeper 2016-03-06 10:18:37 UTC
There is currently no `summary.character()` method so character vectors are summarized by `summary.default()`. Within that method, they are handled by the final `else` routine, which means `summary(character())` will always return the following:

- length
- class
- mode

This is not really informative. It is especially frustrating when summarizing a data.frame that contains a character column. Whereas a factor column returns a nice output:

> summary(iris[, "Species", drop = FALSE])
       Species  
 setosa    :50  
 versicolor:50  
 virginica :50

Character vectors get the less useful output:

> iris$Species <- as.character(iris$Species)
> summary(iris[, "Species", drop = FALSE])
   Species         
 Length:150        
 Class :character  
 Mode  :character

I would propose that `summary.default()` is changed to summarize character vectors as if they were factor, by simply changing the first 4 lines of `summary.default()` to be:

    if (is.factor(object)) 
        return(summary.factor(object, ...))
    else if (is.character(object))
        return(summary.factor(as.factor(object), ...))