Re: [R] Help with basic loop

From: Daniel Malter <>
Date: Sun, 10 Apr 2011 16:06:03 -0700 (PDT)

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 random vectors outside the loop make sense to me only if they are the same length as n.


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, min=0.81, max= 0.89)


If you wanted to store the individual probabilities (task1..3), you would proceed accordingly by defining them outside the loop and storing the value in the loop as the n-th element of that vector just like for prob.


View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 10 Apr 2011 - 23:13:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 11 Apr 2011 - 09:00:28 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive