0

Hi I'm using a for loop in R to generate a series of numbers, calculate an estimate of interest based on these numbers each time and store all iterations of the estimate of interest in a vector. At times the estimate of interest would be NA depending on the numbers generated during that iteration. Is there a way to ask the for loop to re-run itself when the estimate of interest is NA?

Thanks!

Siguza
  • 21,155
  • 6
  • 52
  • 89
chipi3
  • 1
  • 1
  • 1
    It would be better if you provide some example data with the code you are using. – akrun Nov 06 '14 at 04:55
  • There are many potential ways to approach this and I agree with @akrun, it would be much easier to help you with something to work with. I figure you need your vector to reach a predetermined length? – Dominic Comtois Nov 06 '14 at 06:15

1 Answers1

0

You can put the for loop inside a while loop. For example:

while(is.na(result))
{
    # for loop goes here
}

Hope this helps.

Feng Jiang
  • 1,776
  • 19
  • 25
  • Still there is some idea in this answer but the other way around : in the `for` loop, `while the estimate is NA`, do the instructions... – Cath Nov 06 '14 at 07:50