Skip to content

Code to replace nested for loops

1 message · Liaw, Andy

#
You may be able to simplify it further, but just by replacing the whole
inner-most loop with

      opt.mat2[k,j] <- mean(x.mat[kt == x.mat[, nc], j]) 

the computation is instantaneous on my 1.6GHz Pentium M laptop (whereas your
code took just over 7 seconds).

HTH,
Andy