Home > database >  Uniform distribution random sampling
Uniform distribution random sampling

Time:02-17

I need to take 10 samples of size 10 from Uniform distribution (a=0,b=1)

I've tried doing runif(10,0,1) but I do not know how to make R take 10 samples at once.

CodePudding user response:

returns a matrix

replicate(10, runif(10,0,1))

returns a list of 10 vectors

lapply(rep(10, 10), function(x) runif(x,0,1))

CodePudding user response:

replicate will call a function n number of times.

replicate(10, runif(10, 0, 1), simplify = FALSE)
# will return a list; `simplify = TRUE` would return a matrix
  • Related