The function fn
will be called with two
arguments. The first argument is the usual “value vector”
of values
corresponding to this cell in the table,
and the second
is another vector of reference values, determined
by denom
.
The default value of fn
is the percent
function,
defined as function(x, y) 100*length(x)/length(y)
. This
gives the ratio of the number of values in the current cell
relative to the reference values, expressed as a percentage.
Using fn = function(x, y) 100*sum(x)/sum(y)
would give
the percentage of the sum of the values in the current cell to
the sum in the reference set.
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.
The special syntax denom = Equal(...)
will record
each expression in ...
. The
reference set will be the cases with equal values of all
expressions in ...
to those of the current cell.
The similar form denom = Unequal(...)
sets the reference values to be those that differ in any
of the ...
expressions from the current cell. (In
fact, these can be used somewhat more generally; see the
vignette for details.)
Finally, other possible denom
values
are a logical vector, in which
case the values marked TRUE
are used, or anything else, which will
be passed to fn
as y
without any subsetting. (To pass a variable with subsetting,
use the Arguments
pseudo-function instead.)