[R] Simple simulations

robcinm robcinm at gmail.com
Mon Jun 27 23:08:28 CEST 2011


I am taking a basic statistics course this summer, and while the majority of
the class is using a statistical package that came with the book, I am doing
everything in R for practical reasons. Forgive me if there is
documentation/instruction easily available on this topic, but Google and
forums searches left me with nothing.

We are learning about randomness at the moment and are required to create
simulations to use as an example. For the problem in the text, there are 57
numbers with 1 through 20 belonging to the same “group”, meaning the
probability that a number in that group is picked is 20/57, and 21 through
57 are individuals, belonging to no larger group. The point of the exercise
is to simulate the probability of 1 through 20 being chosen at random (with
no replacement) three times in a row through hundreds of trials. This is the
basic syntax I have been using…

sample(c(rep(0, 20), seq(1:37)), 3, replace = F)

That works just fine, but I am wondering if there is a more efficient way of
doing this. Right now, I am hitting the up arrow and hitting “enter”
hundreds of times and making note of each time a trial results in 0,0,0. If
I place this syntax in a rep function, it just repeats the same output of a
single sample x times instead of giving me new data. 


--
View this message in context: http://r.789695.n4.nabble.com/Simple-simulations-tp3628863p3628863.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list