Skip to contents

The check that catches category-mapping corruption on the day it happens instead of years later: cross-tabulates the original against the recoded values and ERRORS unless the realized mapping is a function (each old category to exactly one new category) that matches the declared mapping, with no rows lost.

Usage

morie_crosstab_verify(original, recoded, declared)

Arguments

original, recoded

Parallel vectors (before / after).

declared

Named character vector: the mapping the analyst CLAIMS was applied (c(old = "new", ...)). Identity is assumed for old values absent from declared.

Value

Invisibly, the cross-tabulation (as a data frame), if and only if every check passes.

Examples

x <- c("W", "B", "W"); y <- c("White", "Black", "White")
morie_crosstab_verify(x, y, c(W = "White", B = "Black"))