summary {base}R Documentation

Object Summaries

Description

summary is a generic function used to produce result summaries of the results of various model fitting functions. The function invokes particular methods which depend on the class of the first argument.

Usage

summary(object, ...)

## Default S3 method:
summary(object, ..., digits, quantile.type = 7,
        character.method = c("default", "factor"),
        polar = TRUE)


## S3 method for class 'data.frame'
summary(object, maxsum = 7,
        digits = max(3, getOption("digits")-3), ...)

## S3 method for class 'factor'
summary(object, maxsum = 100, ...)

## S3 method for class 'matrix'
summary(object, ...)

## S3 method for class 'summaryDefault'
format(x, digits = max(3L, getOption("digits") - 3L), zdigits = 4L, ...)
## S3 method for class 'summaryDefault'
 print(x, digits = max(3L, getOption("digits") - 3L), zdigits = 4L, ...)

Arguments

object

an object for which a summary is desired.

x

a result of the default method of summary().

maxsum

integer, indicating how many levels should be shown for factors.

digits

integer (or NULL, see ‘Details’), used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

zdigits

integer, typically positive to be used in the internal zapsmall(*, digits = digits + zdigits) call.

quantile.type

integer code used in quantile(*, type=quantile.type) for the default method.

character.method

a character string, indicating how character vectors are summarized: the "default" method counts unique and blank (whitespace-only, i.e., empty after trimws) elements and computes the nchar range. Choose "factor" to summarize factor(object), resorting to the factor method. Set to NULL to fall back to the generic summary as in R < 4.6.0.

polar

logical, indicating if polar coordinates (modulus and argument) of complex numbers should be summarized rather than Cartesian ones (real and imaginary parts).

...

additional arguments affecting the summary produced.

Details

For factors, the frequency of the first maxsum - 1 most frequent levels is shown, and the less frequent levels are summarized in "(Other)" (resulting in at most maxsum frequencies).

The digits argument may be NULL for some methods specifying to use the default value, e.g., for the "summaryDefault" format() method.

The functions summary.lm and summary.glm are examples of particular methods which summarize the results produced by lm and glm.

Value

The form of the value returned by summary depends on the class of its argument. See the documentation of the particular methods for details of what is produced by that method.

The default method returns an object of class c("summaryDefault", "table") which has specialized format and print methods. The factor method returns an integer vector.

The matrix and data frame methods return a matrix of class "table", obtained by applying summary to each column and collating the results.

References

Chambers J. M., Hastie T. J. (1992). Statistical Models in S. Chapman & Hall, London. ISBN 9780412830402.

See Also

anova, summary.glm, summary.lm.

Examples

## Summarize a data frame (column-wise) -> summary.data.frame
summary(attenu, digits = 4)  # default precision

## Summarize a factor, limiting the output length -> summary.factor
summary(attenu$station, maxsum = 20)

## Summarize a numeric vector -> summary.default
summary(penguins$body_mass)  # includes quantile(), mean, and NAs (if any)
summary(penguins$body_mass, quantile.type = 8)

## Summarize a logical vector -> summary.default
lvec <- penguins$body_mass > 5000
table(lvec)    # excludes NAs by default
summary(lvec)  # shows NAs (if any) and the mode()
summary(as.factor(lvec))  # -> summary.factor

## Summarize a character vector -> summary.default
summary(month.name)
summary(month.name, character.method = "factor")  # =summary(factor(.))
summary(month.name, character.method = NULL)      # as in R < 4.6.0


## show the effect of zdigits for skewed data
set.seed(17); x <- rlnorm(100, sdlog=2)
dput(sx <- summary(x))
sx # exponential format for this data
print(sx, zdigits = 3) # fixed point: "more readable"

## componentwise treatment of complex data (since R 4.6.0):
z <- c(1, 1+1i, 1i, -1+1i, -1, -1-1i, -1i, 1-1i,
       NA_real_, NA_complex_)
(szp <- summary(z))         # using Mod(.) and Arg(.)
(szc <- summary(z, polar = FALSE)) # Re(.) and  Im(.)


[Package base version 4.6.0 Index]