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 2L, 2L, 2L, 2L, 2L, 1L), xxx = c(2L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
2L)), class = "data.frame", row.names = c(NA, -18L))
I need perform cross tab between all categorical variables I.E.
a vs b
a vs c
...
d vs c
m vs n
and so on
i tried use table
command ,but it provided not result that i need,cause i need also calculation of the chi-square test . That why ideally desired result for me would be like this
b total
1 2
a 1 42 54 96
2 40 35 75
total 82 89 171
and p-value for chi-square
Value(empirical) df p-value
chi-square 1,549 1 0,213
How to do crosstab between combinations of variables at once and get similar output results? Namely, the table and the chi-square statistics for it.
Grateful for any help.