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)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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)
回答2:
One could select numbers uniformly from 0...10 and then multiply by 10. Sample code:
q <- 10*sample(seq(0,10), 1000, replace=TRUE)