Learn R Programming

mStats (version 3.2.2)

tab: Tabulation

Description

tab() generates one-way or two-way tabulation of variables.

Usage

tab(data, ..., by = NULL, row.pct = TRUE, na.rm = FALSE, rnd = 1)

Arguments

data

Dataset

...

Variable or multiple variables Colon separator : can be used to specify multiple variables.

by

Varaiable for cross-tabulation

row.pct

TRUE, FALSE or NULL:

TRUE shows row percentages.

FALSE shows column percentages.

NULL shows no percentages.

na.rm

A logical value to specify missing values,

rnd

specify rounding of numbers. See round.

Value

tabulation as list

Details

One-way tabulation

If by is not specified, tab generates one-way tabulation of a variable or multiple variables. ... accepts multiple variables and produces corresponding tabulations.

Tabulation is displayed in Freq. (frequency), Percent. (Relative Frequency) and Cum.Percent. (Cumulative Relative frequency).

tab(data, var1)

tab(data, var1, var2, var3:var5, var10)

Two-way tabulation

Specifying by produces two-way tables. P-values from Chi-squared and Fisher's Exact tests are also shown.

Data type

Tabulation of the whole dataset requires variables to be in either of these data types: character, factor, order factor, logical.

if ... is not specified, tabulation of the whole dataset is produced.

tab(data)

Using colon : spearator

Colon separator : can be used to indicate sequence of variables.

tab(data, var1, var2, var3:var5, var10)

References

Betty R. Kirkwood, Jonathan A.C. Sterne (2006, ISBN:978<U+2013>0<U+2013>86542<U+2013>871<U+2013>3)

Examples

Run this code
# NOT RUN {
## use infert data
data(infert)

## single variable
tab(infert, parity)

## multiple variables
tab(infert, parity, induced, case:pooled.stratum)

## tabulate the whole dataset
tab(infert)



## cross-tabulation
tab(infert, parity, by = case)
tab(infert, parity, by = case, row.pct = FALSE)
tab(infert, parity, by = case, row.pct = NULL)


## multiple variable
tab(infert, age, parity:spontaneous, education, by = case)

# }

Run the code above in your browser using DataLab