muvalues<-c(3,10,15,20); # Differnt values for mu SimSize<-1000 # Simulation Size n<-4 sigma<-3 #Standard Deviation Result<-c() # Storage for the results for each value of mu # Looping Thru mu starts here for (mu in c(3,10,15,20)) { R<-c() for (i in 1:SimSize) {X<-rnorm(n,mu,sigma) xbar<-mean(X) LL<-xbar-(sigma/sqrt(n))*1.96 UL<-xbar+(sigma/sqrt(n))*1.96 R<-cbind(R, (LL < mu) && (UL > mu)) } Result<-rbind(Result,c(mu,mean(R)*100)) } Result<-as.data.frame(Result) # Converts matrix into data frame. names(Result)<-c("mu","CP(%)") #Changes the names of the variables Result