rm(list=ls(all=TRUE)) library(MASS) n=1;muY=0; sigyy=1; ucl=c(); lcl=c(); rl = c();EWMA = c();AEWMA = c(); z = c();deltaf = c() zp=c();zp1= c(); h=0.5764; ld=0.1; Mx=c(); shift=0 for(j in 1:10000) {Mx=c(); for(i in 1:10000) { x=rnorm(n,shift,sigyy) Mx[i]=mean(x) if(i==1) {zp[i]=ld*Mx[i]+(1-ld)*0;} else{zp[i]=ld*Mx[i]+(1-ld)*zp[i-1];} zp1[i]=abs(zp[i]/(1-(1-ld)^i)) if (zp1[i]>3.5) {ld1=1} else if(zp1[i] > 2.5 && zp1[i] <= 3.5) {ld1=0.8} else if(zp1[i] > 1.5 && zp1[i] <= 2.5) {ld1=0.5} else if(zp1[i] > 1 && zp1[i] <= 1.5) {ld1=0.25} else if(zp1[i] >0.75 && zp1[i] <= 1) {ld1=0.20} else if(zp1[i] >0.25 && zp1[i] <= 0.75) {ld1=0.10} else {ld1=0.015} if (i==1) {AEWMA[i] =ld1*Mx[i]+(1-ld1)*0;} else{AEWMA[i] =ld1*Mx[i]+(1-ld1)*AEWMA[i-1];} if(abs(AEWMA[i]) > h) {rl[j]=i;break;} else{rl[j]=0;} } } mean(rl) sd(rl)
I think you are looking for the function rm.list() from the package pracma. It is a wrapper for the function rm.list.default() from the package base. The function rm.list.default() removes all elements of a list that are not TRUE. The function rm.list() is a wrapper for rm.list.default() that also removes the list itself