0
I wanted to make a table more or less like this: A column with the nominal variables and their groups and another column with the average of a variable x for each group of each variable.
With dplyr I can(know) do this but only if I do one group_by()
at a time.
Example: Let’s say in the mtcars dataset my variable x is mpg
while my qualitative variables are vs,am, gear,carb
.
mtcars %>% group_by(vs) %>% summarise(mean(mpg))
mtcars %>% group_by(am) %>% summarise(mean(mpg))
mtcars %>% group_by(gear) %>% summarise(mean(mpg))
mtcars %>% group_by(carb) %>% summarise(mean(mpg))
With this I have the average mpg for each group in each variable but what I’m looking for is a way to, whether by dplyr or another package do these four things at once, so that with this single output I get a table through something like a knit::kable()
Welcome to Sopt. To have your question properly answered, provide a minimum, complete and verifiable example. Check out this Meta post on how to ask a playable question in R.
– Carlos Eduardo Lagosta