let's say I have the following data:
A <- rep(c("A1", "A2", "A3"), 10)
B <- sample(1:5, size=30, replace=TRUE)
C <- sample(c("yes", "no"), size=30, replace=TRUE)
I want to create a table of all three vars, where "A" defines the colums and B and C define the rows.
In rbase, I would do it like this:
data.frame(rbind(table(B, A),
table(C, A)))
This would give the following output:
A1 A2 A3
1 0 3 3
2 2 1 0
3 2 1 2
4 2 4 3
5 4 1 2
no 5 7 3
yes 5 3 7
Variable "A" defines the columns, and variables "B" and "C" define the rows.
My questions are:
How would I do this in tidyverse with dplyr, group_by, summarize?
Is it possible to add the proportions to every cell, so that it would look like this:
A1 A2 A31 0 (0%) 3 (1%) 3 (10%)
2 2 (1%) 1 (0,5) 0 (0%)
3 2 (1%) 1 (0,5) 2 (5%)
4 2 (2%) 4 (2%) 3 (3%)
5 4 (6%) 1 (1%) 2 (2%)
no 5 (7%) 7 (4%) 3 (3%)
yes 5 (3%) 3 (2%) 7 (10%)
Thx in advance....