如何将标准误差置于 R 中 table 中的估计值以下,并转移到 flextable
How to put standard error below estimate in a table in R, and transfer to flextable
我正在使用 apistrat 数据创建汇总统计数据 table,输出为 R 中的 table(希望最终使用 flextable 格式化)。我希望操纵 table 以便每个变量的标准误差直接出现在我收集的 mean/median 值下方。这是一个例子:
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)
一旦变成这种形式,我怎样才能将其转置为 flextable?每当我尝试这样做时,我都会收到以下错误:
> 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()
我正在使用 apistrat 数据创建汇总统计数据 table,输出为 R 中的 table(希望最终使用 flextable 格式化)。我希望操纵 table 以便每个变量的标准误差直接出现在我收集的 mean/median 值下方。这是一个例子:
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)
一旦变成这种形式,我怎样才能将其转置为 flextable?每当我尝试这样做时,我都会收到以下错误:
> 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()