X <- data.frame(x = factor(sample(LETTERS[1:4], 20 , replace = TRUE)),
                z1 = factor(sample(c("Before" ,"After"), 20, replace = TRUE)),
                z2 = factor(sample(c("Red", "Green", "Blue"),20,
                  replace = TRUE)),
                z3 = factor(sample(0:6, 20, replace = TRUE)))
(X <- within(X, z123 <- (z1:z2:z3)[drop = TRUE]))
(tab <- xtabs(~ x + z123, X))
apply(tab, 2, which.max)