prop.table
Express Table Entries as Fraction of Marginal Table

Description

Returns a proportional table with entries that are scaled with a marginal table.

Usage

proportions(x, margin = NULL)
prop.table(x, margin = NULL)

Arguments

x a numeric matrix, a table, or an array.
margin a vector of integers or character strings over which the margins are specified. For example, if x is a matrix, margin=1 indicates rows and margin=2 indicates columns. If character strings, they are expected to be a subset of names(dimnames(x)).

Note that margin specifies the dimensions by which the entries of x are scaled in the result.

If margin is NULL, all entries in x are scaled by the sum of x.

Details

This function returns a table with entries that are proportional to x and the marginal table defined by margin.
Value
a numeric matrix, a table or an array like x. The entries are proportional to x and its marginal table.
Note
Version 4.0.0 of open-source R introduced a new name, proportions, for the old prop.table function, in the hopes that its purpose would be more obvious. The functions are identical.
See Also
sweep, margin.table
Examples
x <- array(1:24, dim = c(4, 3, 2),
    dimnames = list(A=NULL, B=paste0("b",1:3), C=NULL))
proportions(x, c(2, 3))
proportions(x, c("B", "C"))
proportions(x)
Package base version 6.0.0-69
Package Index