[S] Looking for alternative to FOR.. loop

Thomas J. Downing (t_downing@yahoo.com)
Mon, 15 Jun 1998 14:38:55 -0700 (PDT)


Hello:


Below is a function I am working on.

x is 52 * 2001 matrix.
w is a vector of regression weights.
Each column (except the first) is regressed on
the first column.
A 2000 * 1 vector of intercept coefficients is returned.
The function is called numerous times.
Version : 4.0 for Windows.

function(x,w)
{
mkt <- x[ , 1]
m <- matrix(nrow = 2000, ncol = 1)
for(j in 2:2001) {
secj <- x[ , j]
m[j - 1] <- lm(secj ~ mkt,weights = w)$coef[1]
}
m
}

This process takes a surprisingly long time. Is there a way in
which I can avoid the for.. loop and somehow make this function
more efficient?

Thank you in advance!

==
-

Thomas J. Downing
Research Assistant
Quantitative Research
Value Line, Inc.

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news