Consider the vector use = c(1,1,2,2,5,1,2,1,2). I'm trying to replace all the numbers different from 5 to NA before the first number 5 shows up in the sequence: ifelse(use != 5,NA,1). After that the condition should be ifelse(use != 5,0,1). I tried use <- c(1:5,1:5,4) for (val in use) { xx= ifelse(val != 5,NA,1) if (sum(val,na.rm=TRUE) == 1){ break } print(xx) . But it doesn't work. Any tips?
Aucun commentaire:
Enregistrer un commentaire