Learn R Programming

rje (version 1.9)

marginTable: Compute table margin faster

Description

For a contingency table in array form, compute the sum of table entries for a given index.

Usage

marginTable(x, margin = NULL, order = TRUE)
propTable(x, margin = NULL)

Arguments

x

a numeric array

margin

vector of index numbers (1 for rows, etc.)

order

logical indicating whether indices of output should be ordered as in the vector margin?

Value

The relevant marginal table. The class of 'x' is copied to the output table, except in the summation case.

Details

With order = TRUE this is the same as the base function margin.table(), but faster.

With order = FALSE the function is even faster, but the indices in the margin are returned in their original order, regardless of the way they are specified in margin.

propTable() is equivalent to prop.table(), but faster.

Examples

Run this code
# NOT RUN {
m <- matrix(1:4, 2)
marginTable(m, 1)
marginTable(m, 2)

propTable(m, 2)
# }

Run the code above in your browser using DataLab