如何产生从0到100但只有10s的随机整数? [英] How to produce random integer numbers from 0 - 100 but by 10s only?
本文介绍了如何产生从0到100但只有10s的随机整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用R(可能是runif()
或sample()
?),如何产生一组整数随机值?可以说0到100之间的100个随机值,但这些值只能是10s(例如0、10、20、30、40、50、60、70、80、90、100)
Using R (maybe runif()
or sample()
? ), how can one produce a set of integer random values? Lets say 100 random values from 0 - 100, but the values should only be by 10s (e.g 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
推荐答案
sample
将使您轻松进行采样.如果我们创建值的向量,我们希望它应该很容易. seq(0,100,by=10)
将使我们能够构建一个从0开始到100到10结束的序列.
sample
will allow you to do the sampling easily. If we create a vector of the values we want it should be easy enough. seq(0,100,by=10)
will allow us to construct a sequence starting at 0, ending at 100, by 10.
sample(seq(0,100,by=10), 100, replace = TRUE)
这篇关于如何产生从0到100但只有10s的随机整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文