
Last chance! 50% off unlimited learning
Sale ends in
Return the percentages of a cross-tabulation table (2 dimensions or more) with formatting and printing options.
prop(tab, ...)prop_table(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for data.frame
prop(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for matrix
prop(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for tabyl
prop(tab, digits = 1, total = TRUE, percent = FALSE, n = FALSE, ...)
The result is an object of class table
and proptab
.
frequency table
parameters passed to other methods
number of digits to display
if TRUE
, add a column with the sum of percentages and a row with global percentages
if TRUE
, add a percent sign after the values when printing
if TRUE
, lines or columns with a sum of zero, which would generate NaN
percentages, are dropped. Unused for tables of 3 dimensions or more (always `FALSE`).
if TRUE
, display number of observations per row and per column.
rprop
, cprop
, table
, prop.table
## Sample table
data(Titanic)
tab <- apply(Titanic, c(1,4), sum)
## Percentages
prop(tab)
## Percentages with custom display
prop(tab, digits=2, percent=TRUE, total=FALSE, n=TRUE)
## Could be applied to a table of 3 dimensions or more
prop(Titanic)
Run the code above in your browser using DataLab