R Question

Randomly mixing elements in vector R

Supposing I have the vector

x <- c(1,2,3,4,5,6)


Is there any way I could randomly mix its elements?

Or create a vector which would have integer elements from 1 to 6 which do not repeat?

Answer

We need sample to do that

sample(x)

If it needs to be repeated, use the replicated

replicate(3, sample(x))
Comments