如何解决如何将标准误差低于R的表中的估计值,并转换为flextable
我正在使用apistrat数据创建汇总统计表,并将输出作为R表创建(希望最终使用flextable格式化)。我希望对表格进行操作,以使每个变量的标准误差都直接显示在我收集的均值/中值下方。这是一个示例:
dstrata <- apistrat %>%
as_survey_design(strata = stype,weights = pw)
dstrata <- dstrata %>%
mutate(api_diff = api00 - api99)
dstrata %>%
summarise(api_diff = survey_mean(api_diff,vartype="se" ))
api_diff api_diff_se
<dbl> <dbl>
1 32.9 2.08
#so as you can see now,the standard error appears as its own column. Is there a way to reformat the table so it appears like this?
api_diff
<dbl>
1 32.9
(2.08)
一旦采用这种形式,我如何才能将其转置为可弯曲表格?每当我尝试这样做时,都会出现以下错误:
> table=flextable(dstrata)
Error in flextable(dstrata) : is.data.frame(data) is not TRUE
谢谢!
解决方法
有点像:
library(flextable)
library(srvyr)
library(survey)
library(dplyr)
data(api)
# stratified sample
dstrata <- apistrat %>%
as_survey_design(strata = stype,weights = pw)
dstrata <- dstrata %>%
mutate(api_diff = api00 - api99)
dat <- dstrata %>%
summarise(api_diff = survey_mean(api_diff,vartype="se" ))
flextable(dat,col_keys = "api_diff") %>%
compose(j = 1,value = as_paragraph(api_diff," (",api_diff_se,")")) %>%
autofit()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。