Learn R Programming

summarytools (version 0.8.0)

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 = "r", useNA = "ifany", totals = TRUE,
  style = "simple", round.digits = 1, justify = "right",
  omit.headings = FALSE, plain.ascii = TRUE, split.table = 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.

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.

style

Style to be used by pander when rendering output table; One of “simple” (default), “grid” or

round.digits

Number of significant digits to display. Defaults to 1. “rmarkdown”.

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 headings.

plain.ascii

Logical. pander argument; when TRUE, no markup characters will be used (useful when printing to console). Defaults to TRUE when style is “simple”, and FALSE otherwise.

split.table

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

The default plain.ascii = TRUE option is there to make results appear cleaner in the console. To avoid rmarkdown rendering problems, the option is automatically set to FALSE whenever style = "rmarkdown", unless plain.ascii = TRUE is made explicit.

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