I'm trying to repeatedly sample two vectors, x
and y
, 100 times and compute a t-test after each sample. I then want to combine the results into a dataframe using the broom
package. My attempt at doing this is below. However, all I've managed to do is carry out 100 t-tests on the same two vectors.
library(plyr); library(broom)
x <- rnorm(10000, 3, 3)
y <- rnorm(10000, 5, 3)
x_sample <- sample(x, size = 20, replace = FALSE)
y_sample <- sample(y, size = 20, replace = FALSE)
ldply(1:100, function(x) tidy(t.test(x_sample, y_sample)))