Hi, I am doing double for loops to calculate SDs with some weights and wondering if I can get rid of the outer for loop as well. I made a simple examples which is essentially what I am doing.
Thanks for your help! -Young #------------------------------------------------------ # wtd.var is Hmisc package # you can replace the 3 lines inside for loop as # sdx[i,] = apply(x[(i-4):i,],2,var,na.rm=T) # ------------------------------------------------------- x = matrix(rnorm(200),10,20) sdx = matrix(0,10,20) for(i in 5:nrow(x)){ wts = ( 0.5 )^(i-c(1:i)) wts = wts/sum(wts) sdx[i,] = apply(x[1:i,],2,wtd.var,weights=wts,normwt=T, na.rm=T) } [[alternative HTML version deleted]] ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.