Learn R Programming

utile.tables (version 0.3.0)

build_row: Build summary rows

Description

Summarize data into a data.frame with row(s). Includes optional stratification and null hypothesis testing using a factor or logical variable.

Usage

build_row(x, ...)

# S3 method for data.frame build_row( x, y = NA_real_, label = NULL, label.stat = TRUE, stat.pct.sign = FALSE, col.overall = TRUE, col.missing = FALSE, col.test = FALSE, digits = 1, ... )

# S3 method for numeric build_row( x, y = NA_real_, label = NULL, label.stat = TRUE, stat = c("mean", "median"), stat.pct.sign = FALSE, col.overall = TRUE, col.missing = FALSE, test = c("anova", "kruskal", "wilcoxon"), col.test = FALSE, digits = 1, p.digits = 4, ... )

# S3 method for logical build_row( x, y = NA_real_, label = NULL, label.stat = TRUE, inverse = FALSE, stat.pct.sign = FALSE, col.overall = TRUE, col.missing = FALSE, test = c("chisq", "fisher"), test.simulate.p = FALSE, col.test = FALSE, digits = 1, p.digits = 4, ... )

# S3 method for factor build_row( x, y = NA_real_, label = NULL, label.stat = TRUE, stat.pct.sign = FALSE, col.overall = TRUE, col.missing = FALSE, test = c("chisq", "fisher"), test.simulate.p = FALSE, col.test = FALSE, digits = 1, p.digits = 4, ... )

Value

An object of class tbl_df (tibble) summarizing the provided data.

Arguments

x

A data.frame, numeric, factor, or logical. Data to summarize.

...

Arguments passed to the appropriate S3 method.

y

A factor or logical. Data to optionally stratify x by.

label

A character. A label for the summarized data.

label.stat

A logical. Append the summary statistic used to the label.

stat.pct.sign

A logical. Paste a percentage symbol with each frequency. frequency.

col.overall

A logical. Append a column with the statistic for all data. If y is not specified, this parameter is ignored.

col.missing

A logical. Append a column with counts of missing data.

col.test

A logical. Append a column with the name of the statistical test used.

digits

An integer. Number of digits to round to.

stat

A character. Name of the summary statistic to use. Supported options include the mean ('mean') and median ('median') for continuous data.

test

A character. Name of statistical test to compare groups. Supported options: [continuous data] ANOVA linear model ('anova'), Kruskal-Wallis ('kruskal'), and Wilcoxon rank sum ('wilcoxon') tests; [nominal data] Pearson's Chi-squared Test ('chisq') and Fisher's Exact Test ('fisher').

p.digits

An integer. Number of p-value digits to report.

inverse

A logical. For logical data, report frequencies of the FALSE values instead.

test.simulate.p

A logical. Whether to use Monte Carlo simulation of the p-value when testing nominal data.

Examples

Run this code
strata <- as.factor(datasets::mtcars$cyl)

# Create a "count" row from a data.frame for a factor
build_row(x = datasets::mtcars, y = strata)

# Create a row summarizing a numeric by a factor
build_row(label = 'MPG', x = as.numeric(datasets::mtcars$mpg), y = strata)

# Create a row summarizing a logical by a factor
build_row(label = 'VS', x = as.logical(datasets::mtcars$vs), y = strata)

# Create a row summarizing a factor by a factor
build_row(label = 'Carb', x = as.factor(datasets::mtcars$carb), y = strata)

Run the code above in your browser using DataLab