Message-ID: <3EE497F5.6030104@statistik.uni-dortmund.de>
Date: 2003-06-09T14:21:41Z
From: Uwe Ligges
Subject: Loops question
In-Reply-To: <20030609135513.61207.qmail@web20304.mail.yahoo.com>
Ramzi Feghali wrote:
>
> Hello Mr Ripley,
Whom is this mail adressed to? The mailing list R-help or Professor Ripley?
> i was waiting you to ask and if you don't mind if there is a fast way in R to do these loops made with R and that takes a week because my matrix is with thousand of rows.
> I got another method that is more fast and is utilised by many packages : interfacing with other languages", but it is only a question for information
>
So you are going to optimize the following code?
> foo<-function()
> {for (i in 1:(n-1)){
> for (k in (i+1):n){
> b_0
> for (j in 1:m){
> if(bin[i,j]==TRUE&bin[k,j]==TRUE) b_b+1}
> print (b)
> }
> }
> }
>
> Thanks a lot
> Ramzi
There seems to be a logical n x m matrix called bin.
And the sollution of your problem should be solved within seconds by
bin %*% t(bin)
where the upper triangular matrix of the result consists of the results
for all i and k in your loops.
Uwe Ligges