I have the following code
set.seed(30)
nsim <- 50 ## NUMBER OF REPLICATIONS
demand <- c(12,13,24,12,13,12,14,10,11,10)
res <- replicate(nsim, {
load <- runif(10,11,14)
diff <- load - demand ## DIFFERENCE BETWEEN DEMAND AND LOAD
return(sum(diff < 0))
})
res
[1] 6 5 7 4 4 5 4 3 6 4 5 5 5 4 2 5 3 3 3 5 3 2 4 6 5 4 4 3 5 6 4 4 3 6 5 3 5 5 4 3 3
[42] 6 4 4 4 6 6 5 4 5
I have a huge data set and the question is what is the fastest way of calculating the mean for every replication. For example the res in first replication is 6 so the result should be 6/1=6 for the second 6+5/2=5.5 for the third 6+5+7/3=6 and for the last replication is sum(res)/nsim=4.38