tabpct3 | R Documentation |
Produces one, two or multi-way tables with percentages. Requires gdata::interleave. For latex, html output, object can be formatted with knitr::kable
tabpct3(
row,
col = NULL,
collab = NULL,
rowlab = NULL,
pcts = "col",
dp = 2,
total = TRUE,
pval = "exact"
)
row |
factor or numeric vector which will appear in rows |
col |
factor or numeric vector which will appear in columns |
collab |
character vector of column names |
rowlab |
character vector of row names |
pcts |
character string 'both', 'row', or 'col' indicating row, column or both percents (default='col') |
dp |
integer indicating number of decimal places for percents (default=2) |
total |
Logical indicating whether row and column totals are shown (default= TRUE) |
pval |
character string indicating 'exact', 'chisq' or 'none' (default='exact') |
r x c matrix
library(knitr)
yn<-sample(c("Y", "N"), 100, replace=TRUE)
sex<-sample(c("M", "F"), 100, replace=TRUE)
tabpct3(yn)
tabpct3(yn, sex)
tabpct3(yn, sex, dp=1, pcts="row", rowlab=c("No", "Yes"), collab=c("Female", "Male"))
tabpct3(yn, sex, dp=1, pcts="col", rowlab=c("No", "Yes"), collab=c("Female", "Male"))
xx<-tabpct3(yn, sex, dp=1, pcts="col", rowlab=c("No", "Yes"), collab=c("Female", "Male"))
kable(xx, format="latex", caption="My Table")
kable(xx, format="simple", caption="My Table")
ynm<-sample(c("y", "n", "m"), 312, replace=TRUE)
dnum<-sample(c(1:5), 312, replace=TRUE)
tabpct3(dnum, ynm, collab=c("Maybe", "No", "Yes"), pval="chisq")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.