Re: [R] for loop query

2008-12-09 Thread Claudia Beleites
Hi, > Why isn't my loop incrementing i - the outer loop to 2 and then resetting > j=3? It is. It runs out of bounds with j > 26 > Am I missing something obvious? > > for (i in 1:25) > + { > + for (j in i+1:26) You miss parentheses. i + 1 : 26 is i + (1 : 26) as the

Re: [R] for loop query

2008-12-09 Thread Robin Hankin
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

[R] for loop query

2008-12-09 Thread Gerard M. Keogh
Hi all, apologies if this is obvious - but I can't see it and would appreciate some quick help! the matrix mhouse is 26x3 and I'm computing odds ratios. The simple code below "should" compute the odds vector for every pair (325) i.e. 26C2 in cols 1 and 2. On the first i=1 outer loop the inner j