Re: [R] Matrix building to remove for loops

2011-03-16 Thread Brian Pellerin
Thanks, we're almost there. The 3rd statement needs to satisfy fi_2[r,c]<-fi_2[c,r] where rwrote: > Try this: > > fi_2 <- diag(1, i) > fi_2[lower.tri(fi_2)] <- 1 - runif(sum(lower.tri(fi_2))) ^ .5 > fi_2[upper.tri(fi_2)] <- fi_2[lower.tri(fi_2)] > > On Tue, Mar 15, 2011 at 7:51 PM, Brian Pellerin

Re: [R] Matrix building to remove for loops

2011-03-15 Thread Henrique Dallazuanna
Try this: fi_2 <- diag(1, i) fi_2[lower.tri(fi_2)] <- 1 - runif(sum(lower.tri(fi_2))) ^ .5 fi_2[upper.tri(fi_2)] <- fi_2[lower.tri(fi_2)] On Tue, Mar 15, 2011 at 7:51 PM, Brian Pellerin < brianpatrickpelle...@gmail.com> wrote: > Hello R users, > > I would like to reduce the number of for loops i

[R] Matrix building to remove for loops

2011-03-15 Thread Brian Pellerin
Hello R users, I would like to reduce the number of for loops in my code. I build these matrices (5 times). The main diagonal are 1s and the two sides along the main diagonal mirror each other as follows: i<-5 fi<-matrix(0,nrow=i,ncol=i)#floral inhibition matrix for(r in 1:i){ for(c in 1:i){