R: Detailed Statistical Description of Data Frame

descr {collapse} | R Documentation

## Detailed Statistical Description of Data Frame

### Description

`descr` offers a concise description of each variable in a data frame. It is built as a wrapper around `qsu`, but by default also computes frequency tables with percentages for categorical variables, and quantiles and the number of distinct values for numeric variables (next to the mean, sd, min, max, skewness and kurtosis computed by `qsu`).

### Usage

    descr(X, Ndistinct = TRUE, higher = TRUE, table = TRUE,
          Qprobs = c(0.01, 0.05, 0.25, 0.5, 0.75, 0.95, 0.99),
          cols = NULL, label.attr = "label", ...)

    ## S3 method for class 'descr'
    print(x, n = 7, perc = TRUE, digits = 2, t.table = TRUE, summary = TRUE, ...)

    ## S3 method for class 'descr'
    as.data.frame(x, ...)

### Arguments

`X` | a data frame or list of atomic vectors. Atomic vectors, matrices or arrays can be passed but will first be coerced to data frame using `qDF`.
`Ndistinct` | logical. `TRUE` (default) computes the number of distinct values on all variables using `fndistinct`.
`higher` | logical. Argument is passed down to `qsu`: `TRUE` (default) computes the skewness and the kurtosis.
`table` | logical. `TRUE` (default) calls `table` on all categorical variables (excluding Date variables).
`Qprobs` | double. Probabilities for quantiles to compute on numeric variables, passed down to `quantile`. If something non-numeric is passed (i.e. `NULL`, `FALSE`, `NA`, `""` etc.), no quantiles are computed.
`cols` | select columns to describe using column names, indices, a logical vector or a function (e.g. `is.numeric`).
`label.attr` | character. The name of a label attribute to display for each variable (if variables are labeled).
`...` | other arguments passed to `qsu.default`.
`x` | an object of class 'descr'.
`n` | integer. The number of first and last entries to display of the table computed for categorical variables. If the number of distinct elements is `< 2*n`, the whole table is printed.
`perc` | logical. `TRUE` (default) adds percentages to the frequencies in the table for categorical variables.
`digits` | integer. The number of decimals to print in statistics and percentage tables.
`t.table` | logical. `TRUE` (default) prints a transposed table.
`summary` | logical. `TRUE` (default) computes and displays a summary of the frequencies if the size of the table for a categorical variables exceeds `2*n`.

### Details

`descr` was heavily inspired by `Hmisc::describe`, but computes about 10x faster. The performance is comparable to `summary`. `descr` was built as a wrapper around `qsu`, to enrich the set of statistics computed by `qsu` for both numeric and categorical variables.

`qsu` itself is yet about 10x faster than `descr`, and is optimized for grouped, panel data and weighted statistics. It is possible to also compute grouped, panel data and/or weighted statistics with `descr` by passing group-ids to `g`, panel-ids to `pid` or a weight vector to `w`. These arguments are handed down to `qsu.default` and only affect the statistics natively computed by `qsu`, i.e. passing a weight vector produces a weighted mean, sd, skewness and kurtosis but not weighted quantiles.

The list-object returned from `descr` can be converted to a tidy data frame using `as.data.frame`. This representation will not include frequency tables computed for categorical variables, and the method cannot handle arrays of statistics (applicable when `g` or `pid` arguments are passed to `descr`, in that case `as.data.frame.descr` will throw an appropriate error).

### Value

A 2-level nested list, the top-level containing the statistics computed for each variable, which are themselves stored in a list containing the class, the label, the basic statistics and quantiles / tables computed for the variable. The object is given a class 'descr' and also has the number of observations in the dataset attached as an 'N' attribute, as well as an attribute 'arstat' indicating whether the object contains arrays of statistics, and an attribute 'table' indicating whether `table = TRUE` (i.e. the object could contain tables for categorical variables).

### See Also

`qsu`, `pwcor`, Summary Statistics, Fast Statistical Functions, Collapse Overview

### Examples

    ## Standard Use
    descr(iris)
    descr(wlddev)
    descr(GGDC10S)

    as.data.frame(descr(wlddev))

    ## Passing Arguments down to qsu: For Panel Data Statistics
    descr(iris, pid = iris$Species)
    descr(wlddev, pid = wlddev$iso3c)

    ## Grouped Statistics
    descr(iris, g = iris$Species)
    descr(GGDC10S, g = GGDC10S$Region)

[Package collapse version 1.7.6 Index]