Skip to content
Prev 199033 / 398513 Next

Re place only first NA in column

Mike,

Is this what you're trying to do, it avoids the awkward use of a while loop, taking advantage of the ability to vectorize R functions. 

fun <- function() {
  z <- matrix(rbinom(832, 1, prob = 0.048), nrow = 32)
  sum(rowSums(z) == 0)
}

a <- as.matrix(replicate(1000, fun()))