Re: [R] Simple simulations

2011-06-27 Thread jim holtman
Here is another solution if you want to count a sequence like 0 as three overlapping runs of 3 zeros. > x <- sample(c(rep(0,20), rep(1,37)), 100, TRUE) # vector of 1M > z <- rle(x) # get the runs > indx <- which(z$values == 0 & z$lengths > 2) # find the runs > # now determine the number

Re: [R] Simple simulations

2011-06-27 Thread Alexander Engelhardt
Here's a one-liner. Let's see their software do that! sum(replicate(100, sum(sample(c(rep(0, 20), seq(1:37)), 3, replace = FALSE)) == 0)) Am 27.06.2011 23:08, schrieb robcinm: I am taking a basic statistics course this summer, and while the majority of the class is using a statistical packa

Re: [R] Simple simulations

2011-06-27 Thread Jorge Ivan Velez
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

Re: [R] Simple simulations

2011-06-27 Thread Steven Kennedy
#sampling elements x<-c(rep(0, 20), seq(1:37)) #number of simulations to perform sims<-100 #vector to store results results<-c() #using for loop to perform simulations for(i in 1:sims){ #take your sample y<-sample(x,3,replace=FALSE) #check if all elements are zero

[R] Simple simulations

2011-06-27 Thread robcinm
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 sea