Return the row percentages of a two-way frequency table with formatting and printing options.

rprop(tab, ...)

# S3 method for table
rprop(
  tab,
  digits = 1,
  total = TRUE,
  percent = FALSE,
  drop = TRUE,
  n = FALSE,
  ...
)

# S3 method for data.frame
rprop(
  tab,
  digits = 1,
  total = TRUE,
  percent = FALSE,
  drop = TRUE,
  n = FALSE,
  ...
)

# S3 method for matrix
rprop(
  tab,
  digits = 1,
  total = TRUE,
  percent = FALSE,
  drop = TRUE,
  n = FALSE,
  ...
)

# S3 method for tabyl
rprop(tab, digits = 1, total = TRUE, percent = FALSE, n = FALSE, ...)

Arguments

tab

frequency table

...

parameters passed to other methods.

digits

number of digits to display

total

if TRUE, add a column with the sum of percentages and a row with global percentages

percent

if TRUE, add a percent sign after the values when printing

drop

if TRUE, lines or columns with a sum of zero, which would generate NaN percentages, are dropped.

n

if TRUE, display number of observations per row.

Value

The result is an object of class table and proptab.

See also

Examples

## 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%