concept summary() in category R

appears as: summary()
Practical Data Science with R, Second Edition

This is an excerpt from Manning's book Practical Data Science with R, Second Edition.

  • summary()— Provides a summary of almost any R object. summary(uciCar) shows us a lot about the distribution of the UCI car data.
  • Listing 3.1. The summary() command
    setwd("PDSwR2/Custdata")                                                 #1
    customer_data = readRDS("custdata.RDS")
    summary(customer_data)
    ##     custid              sex        is_employed       income           #2
    ##  Length:73262       Female:37837   FALSE: 2351   Min.   :  -6900
    ##  Class :character   Male  :35425   TRUE :45137   1st Qu.:  10700
    ##  Mode  :character                  NA's :25774   Median :  26200
    ##                                                  Mean   :  41764
    ##                                                  3rd Qu.:  51700
    ##                                                  Max.   :1257000
    ##
    ##             marital_status  health_ins                                #3
    ##  Divorced/Separated:10693   Mode :logical
    ##  Married           :38400   FALSE:7307
    ##  Never married     :19407   TRUE :65955
    ##  Widowed           : 4762
    ##
    ##
    ##
    ##                        housing_type   recent_move      num_vehicles   #4
    ##  Homeowner free and clear    :16763   Mode :logical   Min.   :0.000
    ##  Homeowner with mortgage/loan:31387   FALSE:62418     1st Qu.:1.000
    ##  Occupied with no rent       : 1138   TRUE :9123      Median :2.000
    ##  Rented                      :22254   NA's :1721      Mean   :2.066
    ##  NA's                        : 1720                   3rd Qu.:3.000
    ##                                                       Max.   :6.000
    ##                                                       NA's   :1720
    ##       age               state_of_res     gas_usage                    #5
    ##  Min.   :  0.00   California  : 8962   Min.   :  1.00
    ##  1st Qu.: 34.00   Texas       : 6026   1st Qu.:  3.00
    ##  Median : 48.00   Florida     : 4979   Median : 10.00
    ##  Mean   : 49.16   New York    : 4431   Mean   : 41.17
    ##  3rd Qu.: 62.00   Pennsylvania: 2997   3rd Qu.: 60.00
    ##  Max.   :120.00   Illinois    : 2925   Max.   :570.00
    ##                   (Other)     :42942   NA's   :1720

    Most of what we need to know is already in the model summary, which is produced using the summary() command: summary(model). This produces the output shown in figure 7.10.

    Beyond Spreadsheets with R

    This is an excerpt from Manning's book Beyond Spreadsheets with R.

    Once you have subsetted data, you’ll likely want to use it to calculate some summary value(s). The simplest way to do that is the summary() function, which is very useful. It can work with almost any structure of data and provides an overview summary that is specific to the structure. For a numeric vector, it shows the following five-number summary:

    You’ve already seen the summary() function, which gives an overview of an object when you have continuous data. These five-number summaries are useful for picturing how the data is distributed. When you have discrete data, however, things are a little different. If a column is character values, then you don’t get a useful summary. When a column is a factor, summary() gives a count of the values in each level.

    Another way to generate this that does work for character types is the table() function. When used on a factor type, it produces the same output as summary() (except it shows all levels, not just the first few):