Return the row percentages of a cross-tabulation table (2 dimensions or more) with formatting and printing options.
rprop(tab, ...)
# S3 method for class 'table'
rprop(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for class 'data.frame'
rprop(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for class 'matrix'
rprop(
tab,
digits = 1,
total = TRUE,
percent = FALSE,
drop = TRUE,
n = FALSE,
...
)
# S3 method for class 'tabyl'
rprop(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 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.
The result is an object of class table
and proptab
.
cprop
, prop
, table
, prop.table
## Sample table
data(Titanic)
tab <- apply(Titanic, c(1,4), sum)
## Column percentages
rprop(tab)
#> Survived
#> Class No Yes Total
#> 1st 37.5 62.5 100.0
#> 2nd 58.6 41.4 100.0
#> 3rd 74.8 25.2 100.0
#> Crew 76.0 24.0 100.0
#> All 67.7 32.3 100.0
## Column percentages with custom display
rprop(tab, digits=2, percent=TRUE, total=FALSE)
#> Survived
#> Class No Yes
#> 1st 37.54% 62.46%
#> 2nd 58.60% 41.40%
#> 3rd 74.79% 25.21%
#> Crew 76.05% 23.95%
## Could be applied to a table of 3 dimensions or more
rprop(Titanic)
#> , , Age = Child, Survived = No
#>
#> Sex
#> Class Male Female Total
#> 1st NaN NaN NaN
#> 2nd NaN NaN NaN
#> 3rd 67.3 32.7 100.0
#> Crew NaN NaN NaN
#> All 67.3 32.7 100.0
#>
#> , , Age = Adult, Survived = No
#>
#> Sex
#> Class Male Female Total
#> 1st 96.7 3.3 100.0
#> 2nd 92.2 7.8 100.0
#> 3rd 81.3 18.7 100.0
#> Crew 99.6 0.4 100.0
#> All 92.4 7.6 100.0
#>
#> , , Age = Child, Survived = Yes
#>
#> Sex
#> Class Male Female Total
#> 1st 83.3 16.7 100.0
#> 2nd 45.8 54.2 100.0
#> 3rd 48.1 51.9 100.0
#> Crew NaN NaN NaN
#> All 50.9 49.1 100.0
#>
#> , , Age = Adult, Survived = Yes
#>
#> Sex
#> Class Male Female Total
#> 1st 28.9 71.1 100.0
#> 2nd 14.9 85.1 100.0
#> 3rd 49.7 50.3 100.0
#> Crew 90.6 9.4 100.0
#> All 51.7 48.3 100.0
#>