Description Usage Arguments Details Author(s) See Also Examples
tab
generates frequency distribution of a categorical variable.
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)
|
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 |
print.table |
logical value to display formatted outputs |
... |
optional arguments |
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:
Essential Medical Statistics, Betty R. Kirkwood & Jonathan A.C. Sterne, Second Edition. Chapter 3
An Introduction to MEdical Statistics, Martin Bland, Thrid Edition, Chapter 4
Myo Minn Oo (Email: dr.myominnoo@gmail.com | Website: https://myominnoo.github.io/)
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.