Creating data.frame of multiple random samples from a vector in R?

I have the vector X and I would like to generate a data.frame of 6 integer samples of size 4. In other words, I would like to have a data.frame of 6 * 4 dimension. I tried the following the following but its throwing out lenght argument error.


X <- c(4,10,15,100,50,31,311,225,85,91)

S <- replicate(X, = 6, size = 4))

>Solution :

We may need

replicate(4, sample(X, size = 6))


replicate(6, sample(X, size = 4))

Leave a Reply