summarytools (version 0.8.3)

ctable: Cross-Tabulation

Description

Cross-tabulation for a pair of categorical variables (or factors) with either row, column, or total proportions, as well as marginal sums.

Usage

ctable(x, y, prop = st_options("ctable.prop"), useNA = "ifany",
  totals = st_options("ctable.totals"), style = st_options("style"),
  round.digits = 1, justify = "right",
  omit.headings = st_options("omit.headings"),
  plain.ascii = st_options("plain.ascii"), split.tables = Inf,
  dnn = c(substitute(x), substitute(y)), ...)

Arguments

x

First categorical variable - values will appear as row names.

y

Second categorical variable - values will appear in as column names.

prop

Proportions to display; “r” for rows (default), “c” for columns, “t” for total, or “n” for none. This option can be set globally; see st_options.

useNA

Argument passed on to table; One of “ifany” (default), “no”, or “always”.

totals

Logical. Should row and column totals be displayed? Defaults to TRUE. To change this default value globally, see st_options.

style

Style to be used by pander when rendering output table; One of “simple” (default), “grid”, or “rmarkdown” This option can be set globally; see st_options.

round.digits

Number of significant digits to display. Defaults to 1. To change this default value globally, see st_options.

justify

String indicating alignment of columns; one of “l” (left) “c” (center), or “r” (right). Defaults to “r”.

omit.headings

Logical. Set to TRUE to omit heading section. Can be set globally via st_options.

plain.ascii

Logical. pander argument; when TRUE, no markup characters will be used (useful when printing to console). Defaults to TRUE unless style = 'rmarkdown', in which case it will be set to FALSE automatically. To change the default value globally, see st_options.

split.tables

Pander argument that specifies how many characters wide a table can be. Inf by default.

dnn

Names to be used in output table. Vector of two strings; By default, the character values for arguments x and y are used.

Additional arguments passed to pander.

Value

A frequency table of class matrix with added attributes used by print method.

Details

Rmarkdown does not, to this day, support multi-header tables. Therefore, until such support is available, the recommended way to display cross-tables in .Rmd documents is to use `method=render` with the `print()` generic function or with the `view()` function. See package vignettes for examples.

See Also

table, xtabs

Examples

Run this code
# NOT RUN {
data("tobacco")
ctable(tobacco$gender, tobacco$smoker)

# }

Run the code above in your browser using DataLab