tabfreq {tab} | R Documentation |
Create Frequency Table
Description
Creates an I-by-J frequency table comparing the distribution of y
across levels of x
.
Usage
tabfreq(
formula = NULL,
data = NULL,
x = NULL,
y = NULL,
columns = c("xgroups", "p"),
cell = "counts",
parenth = "col.percent",
sep.char = ", ",
test = "chi.fisher",
xlevels = NULL,
yname = NULL,
ylevels = NULL,
compress.binary = FALSE,
yname.row = TRUE,
text.label = NULL,
quantiles = NULL,
quantile.vals = FALSE,
decimals = 1,
formatp.list = NULL,
n.headings = FALSE,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
data |
Data frame containing variables named in |
x |
Vector indicating group membership for columns of I-by-J table. |
y |
Vector indicating group membership for rows of I-by-J table. |
columns |
Character vector specifying what columns to include. Choices
for each element are |
cell |
Character string specifying what statistic to display in cells.
Choices are |
parenth |
Character string specifying what statistic to display in
parentheses. Choices are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
test |
Character string specifying which test for association between
|
xlevels |
Character vector with labels for the levels of |
yname |
Character string with a label for the |
ylevels |
Character vector with labels for the levels of |
compress.binary |
Logical value for whether to compress binary |
yname.row |
Logical value for whether to include a row displaying the
name of the |
text.label |
Character string with text to put after the |
quantiles |
Numeric value. If specified, table compares |
quantile.vals |
Logical value for whether labels for |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display group sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
Value
Examples
# Compare sex distribution by group
(freqtable1 <- tabfreq(Sex ~ Group, data = tabdata))
# Same as previous, but showing male row only and % (SE) rather than n (%)
(freqtable2 <- tabfreq(Sex ~ Group, data = tabdata,
cell = "col.percent", parenth = "se",
compress.binary = TRUE))