Skip to content
Prev 164127 / 398506 Next

for loop query

Hi

start simple!

Work out *each* row combined with *each* row,
to give (in your case) a 26-by-26 matrix.


Only after you have got this working, start thinking about
 making it run faster [eg by
only evaluating the upper triangular entries]

To do a nested loop, do


M <- matrix(0,n,n)

for(i in seq_len(n)){
  for(j in seq_len(n)){
    M[i,j] <-  f(i,j)
    }
}

which will fill in matrix M for you.

HTH

rksh
Gerard M. Keogh wrote: