bCrosstab {Matrix}R Documentation

Create pairwise crosstabulation

Description

Create the pairwise crosstabulation of two or more factors.

Usage

bCrosstab(flist, reorder = TRUE)

Arguments

flist A list of two or more factors. All factors must have the same length.
reorder Logical flag determining if reordering of the factors is allowed.

Value

A list with two components,

flist a possibly reordered copy of the first argument, and
ctab

, itself a list of all pairwise crosstabulation matrices. These include the (diagonal) matrices of “interactions of a factor with itself”, see the example.

See Also

: for factor interaction, xtabs for another cross tabulation function.

Examples

str(esoph)
bCrosstab(with(esoph,list(agegp, alcgp))) $ ctab

grps <- with(esoph, list(age = agegp, alc = alcgp, tob = tobgp))
bCn <- bCrosstab( grps, reorder = FALSE)
stopifnot(all.equal(bCn$flist, grps))
str(bC <- bCrosstab(grps))
bC$ctab$"alc:age" # generally 4 obs. per cell, but not always:
aa.m <- as(bC$ctab$"alc:age", "matrix")
table(aa.m) # #(2,3,4) = (2, 4, 18)
stopifnot(all.equal(as.vector(t(aa.m)),
                    as.vector(table(with(esoph, alcgp:agegp))), tol=0))

[Package Matrix version 0.95-10 Index]