Re: [R] removing for loop

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 04 Jul 2006 - 19:49:14 EST

vincent@7d4.com writes:

> 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.

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

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
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 19:52:10 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.