I would like to randomly reorganize the order of the numbers in a vector, in a simple one-line command?
My particular vector V has 150 entries for each value from 1 to 10:
V <- rep(1:10, each=150)
Yes.
sample(V)
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’).
size
argument of sample
defaults to size <- length(x)
. (Type sample
to see the code that does this.)
Use sample
function
V<-rep(1:10, each=150)
set.seed(001) # just to make it reproducible
sample(V)
sample
. You might want to check out the warnings here for some dangers that go along with just using sample as is.base::sample
to force use ofseq_along
. Also I don't see wheresample/sample.int
callbase::seq()
anyway?