Fastest way to index matrices

Indeed. I had a hard time defining things in the loop, as my primary language is R.