[R] removing for loop

Stefano Calza stecalza at tiscali.it
Tue Jul 4 11:58:46 CEST 2006

I guess outer(b,b,"-") gives what you want


On Tue, Jul 04, 2006 at 11:43:19AM +0200, vincent a 7d4.com wrote:
<vincent>Dear Rusers,
<vincent>Trying to reduce my for loops addiction,
<vincent>could somebody tell me if there are ways to simplify
<vincent>(and perhaps accelerate ?) the following line
<vincent>for (i in 1:N) for (j in 1:N) m[i,j] = b[i]-b[j];
<vincent>(where m is a NxN matrix and b a vector of length N)
<vincent>Thanks for any hint.
<vincent>R-help a stat.math.ethz.ch mailing list
<vincent>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

More information about the R-help mailing list