Можно предварительно сохранить 'n', создав функцию
library(tidyverse)
f1 <- function(n1, n2, mean1 = 1) {
list(t.test(rnorm(n1), rnorm(n2, mean = mean1)),
tibble(number_of_x = n1, number_of_y = n2))
}
t1 <- f1(50, 60)
t2 <- f1(60, 70, 1)
t3 <- f1(80, 90, 2)
map2_df(list(t1[[1]], t2[[1]], t3[[1]]), list(t1[[2]],
t2[[2]], t3[[2]]), ~
tidy(.x) %>%
select(-parameter, -conf.low, -conf.high, -method, -alternative) %>%
bind_cols(.y))
# A tibble: 3 x 7
# estimate estimate1 estimate2 statistic p.value number_of_x number_of_y
# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#1 -0.723 0.348 1.07 -3.77 2.67e- 4 50 60
#2 -1.25 -0.216 1.03 -7.32 2.54e-11 60 70
#3 -2.07 0.0433 2.11 -13.0 3.01e-27 80 90
или используя pmap
list(t1, t2, t3) %>%
transpose %>%
pmap_df(~ tidy(.x) %>%
select(-parameter, -conf.low, -conf.high, -method, -alternative) %>%
bind_cols(.y))
ПРИМЕЧАНИЕ. Выходные значения будутотличается, так как set.seed
не указано