Thanks, we're almost there. The 3rd statement needs to
satisfy fi_2[r,c]<-fi_2[c,r] where r<c.



On Tue, Mar 15, 2011 at 10:06 PM, Henrique Dallazuanna <www...@gmail.com>wrote:

> 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 in my code. I build these
>> matrices (50000 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){ if(r==c){ fi[r,c]<-1 }else if(r<c){ fi[r,c]<-1-runif(1)^.5 }else{
>> fi[r,c]<-fi[c,r] } } }
>> fi
>>
>> Any thoughts?
>>
>> Sincerely,
>> Brian
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to