I have this kind of xtabs
object:
structure(c(1, 4, 7, 2, 5, 8, 3, 6, 9), .Dim = c(3L, 3L),
.Dimnames = structure(list(Var1 = c("A", "B", "C"), Var2 = c("A", "B", "C")),
.Names = c("Var1", "Var2")), class = c("xtabs", "table"))
which gives:
Var2
Var1 A B C
A 1 2 3
B 4 5 6
C 7 8 9
I would like to merge two values of Var1
and Var2
, e.g. "A" and "B", in a new value "D" keeping the contingency matrix properties.
So the result would be for the example:
Var2
Var1 D C
D 12 9
C 15 9