[R] Code to replace nested for loops

2005-03-16 Thread Haynes, Maurice (NIH/NICHD)
Dear list members, How can I replace the nested for loops at then end of the script below with more efficient code? # Begin script__ # Dichotomous scores for 100 respondents on 3 items with # probabilities of a correct response = .6, .4, and .7,

RE: [R] Code to replace nested for loops

2005-03-16 Thread 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 From: Haynes, Maurice