Description Usage Arguments Value Examples
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.
1 | neat_table(table, format = c("html", "latex"), ...)
|
table |
A |
format |
A string specifying output format passed to |
... |
Other arguments passed to |
A kable
object.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.