Re: [R] removing for loop

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

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

HIH,
Stefano

On Tue, Jul 04, 2006 at 11:43:19AM +0200, vincent@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@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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.