xtab: Cross tabulation, contigency table or two-by-two table

Description Usage Arguments Details Author(s) See Also Examples

View source: R/xtab.R

Description

xtab generates cross tabulation of two variables.

Usage

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
xtab(
  x,
  y,
  data = NULL,
  row.pct = TRUE,
  na.rm = FALSE,
  rnd = 1,
  print.table = TRUE
)

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

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

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

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

Arguments

x

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

y

a character, factor or logical object

data

a data frame object (Optional)

row.pct

a logical value: if NULL, a default table without any percentages is produced. If TRUE, row percentages are shown and if FALSE, column percentages.

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

Exploring data before jumping into complex analysis is always a necessity. The first step of an analysis is always to summarize and display data.

xtab produce contigency table.

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

tab

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
xtab(education, induced, infert)
xtab(infert$education, infert$induced)

xtab(spontaneous, induced, infert, row.pct = FALSE) # column percentage
xtab(spontaneous, induced, infert, row.pct = NULL) # DO NOT SHOW PERCENTAGE

# multiple variables
xtab(c(spontaneous, case, induced), education, infert)

## Not run: 
# variables' labels as footnote
infert.new <- labelVars(infert, c(spontaneous, case, induced),
               c("SPONTANEOUS", "CASE YES OR NO", "INDUCED"))
xtab(c(spontaneous, case, induced), education, infert.new)

## End(Not run)

# whole dataset
xtab(infert, case)
xtab(infert, induced)

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