I am preparing a summary statistic for categorical variables in R to put in an academic paper. I am looking for output like this:
Create summary table of categorical variables of different lengths However, I could not find a function for categorical variables.
Here is my small example:
library(dplyr)
library(stargazer)
mtcars %>%
mutate(mpg_cat = ifelse(mpg > mean(mpg), 1,0)) %>%
mutate(mpg_cat= as.factor(mpg_cat)) %>%
mutate(cyl_cat= as.factor(cyl)) %>%
select(cyl_cat, mpg_cat ) %>%
function() %>% ##???
stargazer(summary=FALSE, rownames=FALSE,
#note you have to specify type
type = "html",
#note that the argument is "out" not "file"
out="temp.doc")
and here is the output I have in my mind: https://i.stack.imgur.com/CIdIa.jpg