mercredi 8 novembre 2017

Removing within the for loop some i that the for loop should go over

I would like to use an if statement within a for loop iterating over i such that the if statement removes some i that the loop should go over. So something that looks like that:

iterations <- c(1,2,3,4)
for(i in iterations) { ## i will go from 1 to 4
  if(bla bla bla) {
    d <- bla bla bla ## say, d=4 when i=1
    iterations <- iterations[-d] ## i will now go from 1 to 3
   }
 }

I don't think that this code works, though.

Thank you!

Aucun commentaire:

Enregistrer un commentaire