Learn R Programming

tables (version 0.7.64)

Percent: Percent pseudo-function

Description

The Percent pseudo-function is used to specify a statistic that depends on other values in the table.

Usage

Percent(denom = "all", fn = percent)

Arguments

Pseudo-functions

This is a pseudo-function: it takes the form of a function call, but is never actually called: it is handled specially by tabular.

Details

The function fn will be called with two arguments. The first is the usual vector of values to which this statistic applies, and the second is another vector of reference values, determined by denom. The default function is percent, defined as function(x, y) 100*length(x)/length(y). With the default denom = "all", all values of the analysis variable in the dataset are used as the reference. Other possibilities are denom = "row" or denom = "col", for which the values of the variable corresponding to the current row or column subset are used, or a logical vector, in which case those values are used, or anything else, which will be passed as y.

Examples

Run this code
x <- factor(sample(LETTERS[1:2], 1000, rep=TRUE))
y <- factor(sample(letters[3:4], 1000, rep=TRUE))
tabular( (x + 1) ~ (y + 1)*(RowPct=Percent("row")))

Run the code above in your browser using DataLab