[R] removing for loop

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Tue Jul 4 11:56:49 CEST 2006


try this:

m <- outer(b, b, "-")


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: <vincent at 7d4.com>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, July 04, 2006 11:43 AM
Subject: [R] removing for loop


> Dear Rusers,
>
> Trying to reduce my for loops addiction,
> could somebody tell me if there are ways to simplify
> (and perhaps accelerate ?) the following line
>
> for (i in 1:N) for (j in 1:N) m[i,j] = b[i]-b[j];
>
> (where m is a NxN matrix and b a vector of length N)
>
> Thanks for any hint.
>
> ______________________________________________
> R-help at 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
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list