如何随机化向量 [英] How to randomize a vector

查看:91
本文介绍了如何随机化向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个简单的单行命令随机地将向量中的数字顺序重新组织吗?

I would like to randomly reorganize the order of the numbers in a vector, in a simple one-line command?

我的特定向量V从1到10的每个值都有150个条目:

My particular vector V has 150 entries for each value from 1 to 10:

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

推荐答案

是.

sample(V)

来自?sample:

对于样本",大小"的默认值是项目数 从第一个参数推断出来,以便"sample(x)"生成一个 "x"(或"1:x")的元素的随机排列.

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’).

这篇关于如何随机化向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆