Re: [R] Help with basic loop

2011-04-11 Thread Ivan Calandra
Well, I was quite blind not to change 1 to 1000 in runif() and use replicate()!! It gets even faster if you create prob first. Ivan Le 4/11/2011 10:53, Dennis Murphy a écrit : Hi: Let's assume the lengths of each vector are the same so that they can be multiplied. Here's the timing on my mac

Re: [R] Help with basic loop

2011-04-11 Thread Dennis Murphy
Hi: Let's assume the lengths of each vector are the same so that they can be multiplied. Here's the timing on my machine: > system.time(replicate(1000, { prob<-numeric(1000) + + for (n in 1:1000) { + task1 <- runif(1, min=0.8, max= 0.9) + task2 <- runif(1, min=0.75, max= 0.85) + task3 <- runif(1,

Re: [R] Help with basic loop

2011-04-11 Thread Ivan Calandra
Hi, I think you can do this without a loop (well, replicate() is based on sapply()): prob<-numeric(1000) task1 <- replicate(1000,runif(1, min=0.8, max= 0.9)) task2 <- replicate(1000,runif(1, min=0.75, max= 0.85)) task3 <- replicate(1000,runif(1, min=0.81, max= 0.89)) prob <- task1*task2*task3

Re: [R] Help with basic loop

2011-04-10 Thread Daniel Malter
The loop is correct, you just need to make sure that your result is computed and stored as the n-th element that is returned by the loop. Pick up any manual of R, and looping will be explained there. Also, I would recommend that you draw a random number for every iteration of the loop. Defining the