Alex Rivera | Logout

R: Sample a vector with replacement multiple times

Asked 2012-04-21T23:43:46.267
13

I'd like to sample a vector x of length 7 with replacement and sample that vector 10 separate times. I've tried the something like the following but can't get the resulting 7x10 output I'm looking for. This produces a 1x7 vector but I can't figure out to get the other 9 vectors

x <- runif(7, 0, 1)
for(i in 1:10){
    samp <- sample(x, size = length(x), replace = T)
}
r
Edit
Report

1 Answer

32

This is a very convenient way to do this:

replicate(10,sample(x,length(x),replace = TRUE))
answered 2012-04-21T23:46:24.787

Your Answer