neat_table: Displays a neatly formatted contingency table.

Description Usage Arguments Value Examples

Description

This function provides a default means of converting a contingency table into HTML or LaTeX for publishing. By default, multiple column and row spanning cells are formed to accentuate the hierarchical nature of the data. The output of this function is a kable object and so can be further manipulated.

Usage

1
neat_table(table, format = c("html", "latex"), ...)

Arguments

table

A contintab object, output by contingency_table.

format

A string specifying output format passed to knitr::kable. Currently only 'html' and 'pdf' are supported.

...

Other arguments passed to knitr::kable.

Value

A kable object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# This example uses a dummy data set of whether an individual was treated or not
treat <- data.frame(age=abs(rnorm(100, 60, 20)),
                    sex=factor(sample(c("M", "F"), 100, replace=TRUE)),
                    variant=factor(sample(c("A", "B"), 100, replace=TRUE)),
                    treated=factor(sample(c("Yes", "No"), 100, replace=TRUE),
                                   levels=c("Yes", "No")))
treat$agebin <- cut(treat$age, breaks=c(0, 40, 60, 80, 9999),
                    labels=c("0-40", "41-60", "61-80", "80+"))

tab <- contingency_table(list("Age"='agebin', "Sex"='sex'),
                         outcomes=list('Treated'='treated'),
                         crosstab_funcs=list(freq()),
                         col_funcs=list("Mean age"=summary_mean('age')),
                         data=treat)

# For use in an Rmarkdown that outputs to HTML
neat_table(tab, 'html')

# When outputting to PDF, the \code{booktabs} option produces well-formatted tables
neat_table(tab, 'latex', booktabs=TRUE)

epitab documentation built on May 1, 2019, 7:05 p.m.