tab: Tabulation

Description Usage Arguments Details Author(s) See Also Examples

View source: R/tab.R

Description

tab generates frequency distribution of a categorical variable.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
tab(x, data = NULL, na.rm = FALSE, rnd = 1, print.table = TRUE)

## Default S3 method:
tab(...)

## S3 method for class 'character'
tab(x, data = NULL, na.rm = FALSE, rnd = 1, print.table = TRUE)

## S3 method for class 'list'
tab(x, data = NULL, na.rm = FALSE, rnd = 1, print.table = TRUE)

## S3 method for class 'data.frame'
tab(x, data = NULL, na.rm = FALSE, rnd = 1, print.table = TRUE)

Arguments

x

a character, factor or logical object OR list OR data frame

data

a data frame object (Optional)

na.rm

A logical value to specify missing values, <NA> in the table

rnd

specify rounding of numbers. See round.

print.table

logical value to display formatted outputs

...

optional arguments

Details

tab

produces one-way table of frequencies. Exploring data before jumping into complex analysis is always a necessity. The first step of an analysis is always to summarize and display data.

If variables are specified, all data types are accepted, except for dataframe, it tabulates all variables with three data types: 1) character, 2) factor, and 3) logical.

References:

  1. Essential Medical Statistics, Betty R. Kirkwood & Jonathan A.C. Sterne, Second Edition. Chapter 3

  2. An Introduction to MEdical Statistics, Martin Bland, Thrid Edition, Chapter 4

Author(s)

Myo Minn Oo (Email: dr.myominnoo@gmail.com | Website: https://myominnoo.github.io/)

See Also

xtab, summ, summBy

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Not run: 
# vectors
x <- rep(c("M", "F"), c(40, 60))
tab(x)

# factors
tab(infert$education)
tab(iris$Species)
tab(Species, iris)
tab(agegp, esoph)

# numeric as categorical
tab(case, infert)
tab()

# multiple variables of mixed types
tab(c(infert$case, infert$education, infert$induced))
tab(c(case, parity, induced), infert)

# dataframe
tab(infert)
tab(iris)

# errors: no categorical variables
tab(mtcars)

## End(Not run)

myominnoo/mStats_beta documentation built on Feb. 29, 2020, 8:17 a.m.