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
can't
: [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
Since I didn't want the i to increment in the loop when the condition
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.
initial
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 cases where I
wanted the
,garbage = ,garbage,\n)
}
-Original Message-
From: Peter Dalgaard [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 27, 2007 5:36 PM
To: Mike Jones
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Conditionally incrementing a loop counter: Take 2
Mike Jones wrote:
My apologies for not including
- 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 PROTECTED]
Subject: Re: [R] Conditionally incrementing a loop counter: Take 2
Mike Jones wrote
6 matches
Mail list logo