bCrosstab {Matrix} | R Documentation |
Create the pairwise crosstabulation of two or more factors.
bCrosstab(flist, reorder = TRUE)
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. |
A list with two components,
|
a possibly reordered copy of the first argument, and |
|
, itself a list of all pairwise crosstabulation matrices. These include the (diagonal) matrices of “interactions of a factor with itself”, see the example.
:
for factor interaction,
xtabs
for another cross tabulation function.
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))