Compute and print descriptive statistics for a matrix or data frame, eventually conditioning on another variable.

describe(data, by, detailed = FALSE, ...)
# S3 method for describe
print(x, digits = getOption("digits") - 3, ...)

Arguments

data

a matrix or data frame.

by

a factor or character vector specifying the conditioning variable. This may be a variable included in data or an object defined in the current environment.

detailed

a logical specifying if detailed statistics should be provided.

...

additional arguments to be passed to the generic function.

x

an object of class 'describe'.

digits

the number of significant digits to use.

Details

This function provides simple descriptive statistics for different types of variables, such as numeric, factor, and logical, conditioning or not on another variable.

Author

Luca Scrucca

See also

Examples

data(warpbreaks)
describe(warpbreaks)
#>        Obs  Mean StdDev Min Median Max
#> breaks  54 28.15   13.2  10     26  70
#> 
#>       A  B
#> wool 27 27
#> 
#>          L  M  H
#> tension 18 18 18
describe(warpbreaks, detail = TRUE)
#>        Obs NAs  Mean StdDev Min Q1 Median Q3 Max Skewness Kurtosis
#> breaks  54   0 28.15   13.2  10 18     26 35  70    1.237    1.334
#>     
#> wool Freq. Percent Cum.Percent
#>    A    27      50          50
#>    B    27      50         100
#>        
#> tension Freq. Percent Cum.Percent
#>       L    18   33.33       33.33
#>       M    18   33.33       66.67
#>       H    18   33.33      100.00
describe(warpbreaks, by = wool)
#> ── wool = A ──────────────────────────────────────────────────────────────────── 
#>        Obs  Mean StdDev Min Median Max
#> breaks  27 31.04  15.85  10     26  70
#> 
#>         L M H
#> tension 9 9 9
#> 
#> ── wool = B ──────────────────────────────────────────────────────────────────── 
#>        Obs  Mean StdDev Min Median Max
#> breaks  27 25.26  9.301  13     24  44
#> 
#>         L M H
#> tension 9 9 9