[R] Why doesn't this nested loop work?

Ales Ziberna aleszib2 at gmail.com
Wed Jan 4 17:39:07 CET 2006


Is this what you are searching for?

n.max <- 300
NUM <- 25
id<-0

n.sim <- 10 
j <- (n.max/NUM)*n.sim

results <- matrix(0, nrow=j, ncol=2)

while(NUM <= n.max){

for(i in 1:n.sim){

k <- (NUM/25)*i
id<-id+1
results[id,1] <- k
results[id,2] <- NUM

} 

NUM <- NUM + 25

}

results
<<<


If not, plase give an example how you would like the results to look like!

Best,
Ales Ziberna

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Teresa Nelson
Sent: Wednesday, January 04, 2006 4:44 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Why doesn't this nested loop work?

Hi there,

 

I can get the for-loop to work, I can get the while loop to work.  But I
can't get a for loop to work nested within the while loop - why?  

 

Please help,

Teresa




More information about the R-help mailing list