Learn R Programming

SciencesPo (version 1.02.12)

perc.table: Express table entries as percentage of marginal table.

Description

Same as prop.table() except that it returns percentages rather than proportions.

Usage

perc.table(x, margin = NULL, digits = getOption("digits"), margins = TRUE)

Arguments

x
A frequency table likely constructed with table().
margin
A numeric representing an index, or vector of indices, to generate the margin for -- margin=1 computes row percentages, margin=2 computes column percentages, and margin=NULL (default) produces table percentages.
digits
A numeric indicating the number of decimals to round the percentages to..
margins
A logical indicating whether marginal totals should be appended to the table or not. If addMargins=TRUE then the appended marginal totals will correspond to which margin is chosen with margin=.

Value

  • Same type as x except with percentages of a margin rather than frequencies.

Examples

Run this code
Aye <- sample(c("Yes", "Si", "Oui"), 177, replace = TRUE)
Bee <- sample(c("Hum", "Buzz"), 177, replace = TRUE)
( A <- table(Aye, Bee) )

## what prop.table() would look like
prop.table(A,margin=1)

## modified for percTable
# row percentages
perc.table(A,margin=1)
perc.table(A,margin=1,digits=1)
# column percentages
perc.table(A,margin=2)
# table percentages
perc.table(A)

## No marginal totals
perc.table(A,margins=FALSE)

Run the code above in your browser using DataLab