tab {mStats} | R Documentation |
Tabulation
Description
tab()
generates one-way or two-way tabulation of variables.
If no variables are specified, tabulations for all the variables
in the dataset are generated.
Usage
tab(data, ..., by = NULL, row.pct = TRUE, na.rm = FALSE, digits = 1)
Arguments
data |
data.frame |
... |
variable name or names of multiple variables |
by |
variable name for bivariate analysis |
row.pct |
|
na.rm |
logical: if |
digits |
specify rounding of numbers. |
Details
One-way tabulation
If by
is not specified, tab
generates one-way tabulation of
a variable or multiple variables. The table is displayed
in Freq.
(frequency), Percent
(Relative Frequency) and Cum.
(Cumulative Relative frequency).
Two-way tabulation
Specifying by
leads to two-way tabulation. By default,
row percentages are displayed along with count data. If row.pct
is set to NULL
, it shows a count table without percentages. If set to
FALSE
, a table with column percentages is generated. P-values from
Chi-squared
and Fisher's Exact
tests are also shown, regardless
of displaying percentages.
Tabulating the whole dataset
This is helpful when the dataset has been processed and finalized.
The final dataset can be fed into the function without
inputting any variables. This automatically filters and generates
tables on variables with possible data types for tabulation. These
data types include character
, factor
, order factor
, and logical
.
Using colon :
to tabulate multiple variables
A colon separator :
can be used to generate one-way or two-way
tables efficiently.
Labels
Labels for corresponding variables are displayed below the table.
Value
A list with tab
class containing three sets of data.frame type:
tabulation result,
tabulation result without any format,
labels for corresponding variables.
Author(s)
Email: dr.myominnoo@gmail.com
Website: https://myominnoo.github.io/
Examples
## One-way tabulation
tab(infert, education)
tab(infert, education, parity:spontaneous)
tab(infert)
## Two-way tabulation
tab(infert, education, by = case)
tab(infert, education, parity:spontaneous, by = case)
tab(infert, by = case)