How can i write something like this
<code>res <- rep(NA, 10)
fu <- function() sample(c("yes","no"),1)
i <- 0
while(i<10){
what <- fu()
if(what=="yes"){
i <- i+1
res[i] <- what
}
}
</code>
<code>res <- rep(NA, 10)
fu <- function() sample(c("yes","no"),1)
i <- 0
while(i<10){
what <- fu()
if(what=="yes"){
i <- i+1
res[i] <- what
}
}
</code>
res <- rep(NA, 10)
fu <- function() sample(c("yes","no"),1)
i <- 0
while(i<10){
what <- fu()
if(what=="yes"){
i <- i+1
res[i] <- what
}
}
in a more acceptable style for R, without making unnecessary iterations, and stop when the res
is completely filled.