Dear All, I have the following code which works fine but takes 16+ hours to run and I was hoping someone could give me a hint as to how I could make it more efficient. Let me explain what the code is supposed to do. Each single row of the m.o.f matrix (n*p dim) has to go through the following operation Dm*m.o.f[i]^alpha1m where both Dm and alpha1m have n*1 dimensions. Each row of the m.o.f is to be evaluated n times for the different values of alpha1m and Dm. My code changes the Dm and alpha1m (n*1) matrices into (n*p) matrices (not shown below, done only 1 time) and also change the (1*p) m.o.f row into a m.o (n*p) matrix (shown below, done n times). For each of the n rows of the m.o.f matrix we repeat this operation which we record in the temp matrix. The third line of the loop multiplies for each row, the columns of the matrix and takes the resultant mean of the vector. I know I should use the whole object approach somehow but after many tries I gaave up for the long approach. I know the explanation above is rather long and I apologize for that, any hint/help will be greatly appreciated. for (i in 1:numrows) { mo.o<-t(array(m.o.f[i,],dim=c(numcols,numrows))) t<-Dm*m.o^alpha1m l1[i]<-mean(apply(t,1,"prod")) } Best Regards,
--------------------------------- [[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.