I am trying to create a data table that sorts each of the variable rows into 2 different subgroups. Here is a reproducible example to hopefully clarify what I'd like to do.
table <- mtcars %>%
group_by(vs) %>%
summarise(MPG=mean(mpg),DRAT=mean(drat))
table=t(table)
table
[,1] [,2]
vs 0.000000 1.000000
MPG 16.616667 24.557143
DRAT 3.392222 3.859286
#here is what I would like the output to look like, but am unsure how to do create it (some of these numbers I just made up)
**[,1] [,2]
vs 0.000000 1.000000
MPG (overall) 16.616667 24.557143**
MPG (am=1) 14 13
MPG (am=0) 11 12
**DRAT (overall) 3.392222 3.859286**
DRAT (am=1) 3.1 3.6
DRAT (am=0) 4 4
So with that table in mind, I want to modify it so for the MPG and DRAT variables, there are two subcategories based on whether cars are in the 0 or 1 group for the am variable in the data set. I'm having a hard time telling R to have column groups for the vs variable, and also separately analyzing the am groups (0 or 1) for each row and displaying that in the table. Thank you!