如何将标准误差低于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()

enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...