50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

DemographicTable (version 0.1.10)

sumstat: Summary Statistics

Description

Provide the summary statistics of an R object

Usage

.sumstat(x, fmt, ...)

# S3 method for default .sumstat(x, fmt = "%.2f", ...)

# S3 method for factor .sumstat(x, ...)

# S3 method for ordered .sumstat(x, ...)

# S3 method for character .sumstat(x, ...)

# S3 method for logical .sumstat(x, ...)

Value

Function .sumstat returns a character scalar.

Arguments

x

an R object

fmt

(optional) character scalar, only for function .sumstat.default, see function sprintf

...

additional parameters, currently not in use

Details

Function .sumstat.default accepts all R objects of typeof double and integer. Statistics of mean, sd and range are reported. If the normality assumption via shapiro.test is not satisfied, then median and mad are also reported.

Examples

Run this code
x = c(rpois(n = 20L, lambda = 2), NA_integer_)
.sumstat(x)

# factor 
x = state.region
x[2L] = NA_integer_
.sumstat(x)

# binary
.sumstat(c(TRUE, FALSE, TRUE, NA))
.sumstat(c(TRUE, FALSE, TRUE))
.sumstat(c(FALSE, FALSE, NA))
.sumstat(c(FALSE, FALSE, FALSE))
.sumstat(c(NA, NA, NA))

Run the code above in your browser using DataLab