m = 100000 #number of samples n = 10 #size of a sample mu = 5 #expectation var = 4 #variance A = matrix( rnorm(n*m,mean=mu,sd=sqrt(var)), m, n) #generate a vector of n*m random variable with mean mu e variance var and trasnform it in a matrix m by n avg = rowMeans(A) #compute the average of each sample sum(abs(avg-mu)<=sqrt(var/10)*1.96) #count how many times the expercation falls in the confidence interval