tabpct3: Tables with percentages

View source: R/tabfunctions.R

tabpct3R Documentation

Tables with percentages

Description

Produces one, two or multi-way tables with percentages. Requires gdata::interleave. For latex, html output, object can be formatted with knitr::kable

Usage

tabpct3(
  row,
  col = NULL,
  collab = NULL,
  rowlab = NULL,
  pcts = "col",
  dp = 2,
  total = TRUE,
  pval = "exact"
)

Arguments

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')

Value

r x c matrix

Examples

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")

wadetj/timsRstuff documentation built on April 12, 2025, 5:54 p.m.