【发布时间】:2019-02-27 12:04:02
【问题描述】:
我想在 t 检验表中添加值的数量。这是我的示例代码:
library(broom)
library(purrr)
t1 <- t.test(rnorm(50), rnorm(60))
t2 <- t.test(rnorm(60), rnorm(70, 1))
t3 <- t.test(rnorm(80), rnorm(90, 2))
现在我用 broom 和 purrr 包将它们变成一个数据框(然后可以打印为表格),我得到了这张表格:
tab <- map_df(list(t1, t2, t3), tidy)
tab %>% select(-parameter, -conf.low, -conf.high, -method, -alternative)
# A tibble: 3 x 5
estimate estimate1 estimate2 statistic p.value
<dbl> <dbl> <dbl> <dbl> <dbl>
1 -0.0542 -0.178 -0.123 -0.260 7.95e- 1
2 -1.24 -0.214 1.03 -6.48 1.88e- 9
3 -2.30 -0.231 2.07 -14.6 2.81e-31
现在我想添加 2 个新列,其中包含 x 的数量和 y 的数量。 这是我想要的输出:
# A tibble: 3 x 5
estimate estimate1 estimate2 statistic p.value number_of_x number_of_Y
<dbl> <dbl> <dbl> <dbl> <dbl>
1 -0.0542 -0.178 -0.123 -0.260 7.95e- 1 50 60
2 -1.24 -0.214 1.03 -6.48 1.88e- 9 60 70
3 -2.30 -0.231 2.07 -14.6 2.81e-31 80 90
有人可以帮我创建这个决赛桌吗?
【问题讨论】: