[英]Calculate age standardised rates by sub-group with confidence intervals in R
[英]Calculate mean and bootstrap confidence intervals by group
如何按组计算平均值和引导 CI,并将答案作为 dataframe 返回?
我已经设法完成了大部分工作,但我的答案以列表的形式返回。 下面的可重现示例。 任何帮助表示赞赏。
library(dplyr); library(Hmisc)
graph <- iris %>%
+ select(Petal.Length, Species) %>%
+ group_by(Species) %>%
+ group_map(~ smean.cl.boot(., conf.int = .95, B = 1000, na.rm = TRUE))
您可以将bind_rows
添加到您的尝试中。
library(dplyr)
library(Hmisc)
iris %>%
select(Petal.Length, Species) %>%
group_by(Species) %>%
group_map(~ smean.cl.boot(., conf.int = .95, B = 1000, na.rm = TRUE)) %>%
bind_rows()
# Mean Lower Upper
# <dbl> <dbl> <dbl>
#1 1.46 1.42 1.51
#2 4.26 4.13 4.38
#3 5.55 5.4 5.70
或者另一种方式是:
iris %>%
select(Petal.Length, Species) %>%
group_by(Species) %>%
summarise(data = list(smean.cl.boot(cur_data(), conf.int = .95, B = 1000, na.rm = TRUE))) %>%
tidyr::unnest_wider(data)
# Species Mean Lower Upper
# <fct> <dbl> <dbl> <dbl>
#1 setosa 1.46 1.42 1.51
#2 versicolor 4.26 4.13 4.39
#3 virginica 5.55 5.40 5.70
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.