I want to create a 2 dimensional array of 100,000 by 100,000 that contains values of Cp. so i get Cp[1,] ,Cp[2,] , Cp[3,] and so on then find all the mean for Cp[1,] and store it as meanCp[1], mean of Cp[2,] and store as meanCp[2]. Is there a better and faster way of doing this than i have here?
K=0.5
x=numeric()
stdCp=numeric()
meanCp=numeric()
u0=0
Cp <- matrix(0,100000,100000)
for (j in 1:100000) {
x=rnorm(100000,0,1)
for (i in 1:100000) {
if (j==1){
Cp[j,i]= max(0,x[i]-(u0+K))
} else {
Cp[j,i]= max(0,x[i]-(u0+K)+Cp[j-1,i])
}
}
meanCp[j]=mean(Cp[j,])
stdCp[j]=sd(Cp[j,])
}
meanCp
so for example meanCp[1] gives me a value between 0.19 and 0.20