user1723765 user1723765 - 1 year ago 167
R Question

How to randomize a vector

I have a vector V with 150 entries for each value from 1 to 10.

V<-rep(1:10, each=150)

I would like to randomly reorganize the order of the numbers in this vector.

Can this be done with a simple 1 line command?

Answer Source



From ?sample:

For ‘sample’ the default for ‘size’ is the number of items inferred from the first argument, so that ‘sample(x)’ generates a random permutation of the elements of ‘x’ (or ‘1:x’).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download