Hi robcinm,
You might also consider:
# data
x <- c(rep(0, 20), 1:37)
# number of simulations
B <- 1000
# result: TRUE/FALSE
out <- replicate(B, {
y <- sample(x, 3, replace = FALSE)
all(y == 0)
})
mean(out)
HTH,
Jorge
On Mon, Jun 27, 2011 at 5:08 PM, robcinm <> wrote:
> 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.
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.