Re: [R] removing for loop

From: Stefano Calza <>
Date: Tue 04 Jul 2006 - 19:58:46 EST

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


On Tue, Jul 04, 2006 at 11:43:19AM +0200, 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> mailing list
<vincent>PLEASE do read the posting guide! mailing list PLEASE do read the posting guide! Received on Tue Jul 04 20:14:53 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 04 Jul 2006 - 22:15:28 EST.

Mailing list information is available at Please read the posting guide before posting to the list.