You can use (*)apply functions:

sapply(paste("V1 ~", names(dat)[2:5]), function(f)coef(lm(as.formula(f),
data = dat)))

Where V1 is your first column and dat is your data.frame object.

On Mon, Jun 15, 2009 at 6:42 PM, Oscar Bayona <osba...@gmail.com> wrote:

> Hi I have a simple question. I want to run a "n times" a simple linear
> regession and save beta in a matrix but I´m not able.
>
> Imagine:
>
> Data.txt is a 10*5 file and want to run 4 different stimations always
> regressing first column on the rest.
>
> So I try this:
>
> First I run Data on memory
>
> This is my function
>
> mrp <- function(){
> mr<-matrix(0,4,1)
> for(i in 1:4)
> r(i)=lm(dat(,i+1)~dat(,1)
>  mr[i] <- coefficients(r(i)))
> }
>
> I execute mrp usin source file choose option but nothing happens....
>
> Where I´m wrong?
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to