我想随机重组的顺序的数字在一个向量,在一个简单的一行命令?
我的特定向量 V 有150个条目,每个值从1到10:
V <- rep(1:10, each=150)
Yes.
sample(V)
From ?sample:
?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’).
Use sample function
sample
V<-rep(1:10, each=150) set.seed(001) # just to make it reproducible sample(V)