Return the column percentages of a two-way frequency table with formatting and printing options.
cprop(tab, ...)
# S3 method for table
cprop(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for data.frame
cprop(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for matrix
cprop(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for tabyl
cprop(tab, digits = 1, total = TRUE, percent = FALSE, n = FALSE, ...)
frequency table
parameters passed to other methods.
number of digits to display
if TRUE
, add a row with the sum of percentages and a column 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.
if TRUE
, display number of observations per column.
The result is an object of class table
and proptab
.
rprop
, prop
, table
, prop.table
## Sample table
data(Titanic)
tab <- apply(Titanic, c(4,1), sum)
## Column percentages
cprop(tab)
#> Class
#> Survived 1st 2nd 3rd Crew All
#> No 37.5 58.6 74.8 76.0 67.7
#> Yes 62.5 41.4 25.2 24.0 32.3
#> Total 100.0 100.0 100.0 100.0 100.0
## Column percentages with custom display
cprop(tab, digits=2, percent=TRUE, total=FALSE)
#> Class
#> Survived 1st 2nd 3rd Crew
#> No 37.54% 58.60% 74.79% 76.05%
#> Yes 62.46% 41.40% 25.21% 23.95%