I want 100 integers. Each integer, x, can be in the range 1 =< x => 10. Does the following code give 1 and 10 the same chances to be selected as 2:8? round(runif(100, min = 1, max = 10)) -- Hans Ekbrand -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Digital signature URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100429/5eeb7e8f/attachment.bin>
You can always take a look. If you use a much bigger sample size it will be obvious: hist(round(runif(1000000, min = 1, max = 10))) I'd use instead: hist(sample(1:10, 1000000, replace=TRUE)) Sarah On Thu, Apr 29, 2010 at 12:39 PM, Hans Ekbrand <hans at sociologi.cjb.net> wrote:> I want 100 integers. Each integer, x, can be in the range 1 =< x => 10. > > Does the following code give 1 and 10 the same chances to be selected as > 2:8? > > round(runif(100, min = 1, max = 10)) > > -- > Hans Ekbrand >-- Sarah Goslee http://www.functionaldiversity.org
Hans Ekbrand wrote:> I want 100 integers. Each integer, x, can be in the range 1 =< x => 10. > > Does the following code give 1 and 10 the same chances to be selected as > 2:8? > > round(runif(100, min = 1, max = 10))If you just want to sample integers, use ?sample
Reasonably Related Threads
- how to make list() return a list of *named* elements
- how to word-wrap text in labels in plots?
- which is the fastest way to make data.frame out of a three-dimensional array?
- ploting a comparison of two scores, including the labels in the plot
- simple usage of "for"