Is there a package that lets me produce tables such as this -
I am using excel to show my desired output. I'm using the mtcars dataset as an example. Here I group Carb sizes into small, medium and large and show the count and mean mpg by those sizes. I've been exploring the gt package but still struggling to produce something like this exactly. What I can see from this tutorial is that gt table can add summary lines below each group, however I would like to add the summaries (count, mean etc) as columns, and not rows below each group.
Lastly when I try to replicate the the tutorial in the link above using the mtcars dataset, I get the following error -
Error in rlang::eval_tidy(expr = var_expr, data = data_tbl, env = emptyenv()) :
object 'mean.mpg' not found
Here is my code;
mtcars %>% select(mpg, carb) %>% mutate(size = case_when( carb %in% c(1, 2) ~ "Large", carb %in% c(4, 4) ~ "Medium", TRUE ~ "Small" )) %>% group_by(carb, size) %>% summarise(count = n(), mean.mpg = mean(mpg)) %>% ungroup() %>% gt(groupname_col = "size") %>% summary_rows(groups = T, columns = mean.mpg, fns = list( average = "mean" ))
I appreciate any help.