首页 > 解决方案 > 分类变量的统计摘要 - 学术论文

问题描述

我正在为 R 中的分类变量准备一个汇总统计数据,以放入学术论文中。我正在寻找这样的输出:

创建不同长度的分类变量的汇总表 但是,我找不到分类变量的函数。

这是我的小例子:

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")

这是我脑海中的输出: https ://i.stack.imgur.com/CIdIa.jpg

标签: rfunctionsummary

解决方案


假设您有数据来填充这样的模板,请使用该库kableExtra

https://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf

(见第 14-20 页)

你最好学习如何处理表格,这个库也使用%>%你已经知道的符号。


推荐阅读