[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

HIH,
Stefano


On Tue, Jul 04, 2006 at 11:43:19AM +0200, vincent a 7d4.com wrote:
<vincent>Dear Rusers,
<vincent>
<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>
<vincent>for (i in 1:N) for (j in 1:N) m[i,j] = b[i]-b[j];
<vincent>
<vincent>(where m is a NxN matrix and b a vector of length N)
<vincent>
<vincent>Thanks for any hint.
<vincent>
<vincent>______________________________________________
<vincent>R-help a stat.math.ethz.ch mailing list
<vincent>https://stat.ethz.ch/mailman/listinfo/r-help
<vincent>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



More information about the R-help mailing list