I'm trying to make sense of some data with a two-way table (using gmodels - but I am open to doing this in a tidyverse way too) and I can't work out how to control the order of the columns and the rows.
I would like TRUE to be the first column, and TRUE to be the first row. Here's some code I have.
library(gmodels)
# some dummy data
df <- tibble(green = c(TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE),
pink = c(FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE))
CrossTable(
df$pink,
df$green,
prop.r = FALSE,
prop.t = FALSE,
prop.c = FALSE,
prop.chisq = FALSE,
chisq = FALSE
)
The above code produces output in a different column/row order than I want:
| df$green
df$pink | FALSE | TRUE | Row Total |
-------------|-----------|-----------|-----------|
FALSE | 2 | 2 | 4 |
-------------|-----------|-----------|-----------|
TRUE | 4 | 1 | 5 |
-------------|-----------|-----------|-----------|
Column Total | 6 | 3 | 9 |
-------------|-----------|-----------|-----------|
But what I want to see is something like this (which I've done by hand):
| df$green
df$pink | TRUE | FALSE | Row Total |
-------------|-----------|-----------|-----------|
TRUE | 1 | 4 | 5 |
-------------|-----------|-----------|-----------|
FALSE | 2 | 2 | 4 |
-------------|-----------|-----------|-----------|
Column Total | 3 | 6 | 9 |
-------------|-----------|-----------|-----------|
thanks!