Re: [R] Conditionally incrementing a loop counter: Take 2

2007-12-28 Thread John Fox
a/jfox > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org] On Behalf Of Mike Jones > Sent: December-27-07 6:08 PM > To: Peter Dalgaard > Cc: [EMAIL PROTECTED] > Subject: Re: [R] Conditionally incrementing a loop counter: Take 2 > &

Re: [R] Conditionally incrementing a loop counter: Take 2

2007-12-28 Thread Jim Lemon
Mike Jones wrote: > >Hi, >I am trying a for loop from 1 to 10 by 1. However, if a condition >does not get met, I want to "throw away" that iteration. So if my >loop is for (i in 1:10) and i is say, 4 and the condition is not met >then I don't want i to go up to 5. Is there a way to do that? I

Re: [R] Conditionally incrementing a loop counter: Take 2

2007-12-27 Thread Peter Dalgaard
l Message- >> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] >> project.org] On Behalf Of Mike Jones >> Sent: December-27-07 6:08 PM >> To: Peter Dalgaard >> Cc: [EMAIL PROTECTED] >> Subject: Re: [R] Conditionally incrementing a loop counter: Take 2 >>

Re: [R] Conditionally incrementing a loop counter: Take 2

2007-12-27 Thread Mike Jones
;- i + 1 } else{ garbage <- garbage+1 } cat("i = ",i,"garbage = ",garbage,"\n") } -Original Message- From: Peter Dalgaard [mailto:[EMAIL PROTECTED] Sent: Thursday, December 27, 2007 5:36 PM To: Mike Jones Cc: [EMAIL

Re: [R] Conditionally incrementing a loop counter: Take 2

2007-12-27 Thread Peter Dalgaard
Mike Jones wrote: > My apologies for not including a working example. > > Here it is: > > for (i in 1:10){ >cat("initial i = ",i,"\n") >x <- runif(1) >if (x > 0.7){ > i <- i-1 >} >cat("second i = ",i,"\n") > } > > When I ran this i got what follows, so there were four c

[R] Conditionally incrementing a loop counter: Take 2

2007-12-27 Thread Mike Jones
My apologies for not including a working example. Here it is: for (i in 1:10){ cat("initial i = ",i,"\n") x <- runif(1) if (x > 0.7){ i <- i-1 } cat("second i = ",i,"\n") } When I ran this i got what follows, so there were four cases where I wanted the i not to increment.