Suppose I have A, an n x m matrix, each element is an integer (an index). I also have B, an n x l x m array. I need C, where
C[n,m] = B[n, A[n, m], m] I am currently using loops, what would be the "R way" to do this? Another question: let A[n, m] <- argmax_l B[n, l, m] what would be the nicest way of doing this? Currently I am using max.col and a single loop, going though the n's. Background: I solving a discrete-space dynamic programming problem, A is the optimal policy, C is the value function. The structure of the problem allows me to use matrices like above, instead of (n * m) x (n x m) square matrices. Thanks Tamas -- Tamás K. Papp E-mail: [EMAIL PROTECTED] (preferred, especially for large messages) [EMAIL PROTECTED] Please try to send only (latin-2) plain text, not HTML or other garbage. ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html