【发布时间】:2019-08-05 02:20:17
【问题描述】:
我正在为 R 中的分类变量准备一个汇总统计数据,以放入学术论文中。我正在寻找这样的输出:
Create summary table of categorical variables of different lengths 但是,我找不到分类变量的函数。
这是我的小例子:
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
【问题讨论】:
-
您是否尝试过您分享的链接中给出的答案?
-
是的。没有一个函数适用于分类变量。
-
还有几个问题:(i)为什么注释是
function() %>% ##????; (ii) 您需要的最终输出是什么?比如什么类型的汇总统计,你需要它是什么格式?