Hola, me gustaria saber como óptimizar el siguiente código para que corra
en menos tiempo de ejecución:

sim1 <- function(nreps)  {
   nb1 <- 10  # 10 blue marbles in Urn 1
   n1 <- 18  # number of marbles in Urn 1 at 1st pick
   n2 <- 13  # number of marbles in Urn 2 at 2nd pick
   count <- 0  # number of repetitions in which get blue from Urn 2
   for (i in 1:nreps)  {
      nb2 <- 6  # 6 blue marbles orig. in Urn 2
      # pick from Urn 1 and put in Urn 2; is it blue?
      if (runif(1) < nb1/n1) nb2 <- nb2 + 1
      # pick from Urn 2; is it blue?
      if (runif(1) < nb2/n2) count <- count + 1
   }
   return(count/nreps)  # est. P(pick blue from Urn 2)
}


Gracias,

Tania

	[[alternative HTML version deleted]]

