Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在一个简单的单行命令中随机重组向量中数字的顺序?
我的特定向量 V 对于从 1 到 10 的每个值有 150 个条目:
V <- rep(1:10, each=150)
是的。
sample(V)
来自?sample:
?sample
对于“sample”,“size”的默认值是从第一个参数推断的项目数,因此“sample(x)”会生成“x”(或“1:x”)元素的随机排列。
使用sample功能
sample
V<-rep(1:10, each=150) set.seed(001) # just to make it reproducible sample(V)