Christian Hoffmann <christian.hoffmann <at> wsl.ch> writes:

> 
> Hi all,
> 
> I just cannot think of how to do it:
> I want to take the first variable (column) of a data frame and regress 
> it against all other variables.
> 
> bla <- function (dat) {
>    reg <- lm(whateverthefirstofthevariablenamesis ~., data=dat)
>    return(reg)
> }

Andy has already given a particularly concise solution but if your
variable is not in first position then you could rearrange the 
order of the variables to allow his solution or use this which works 
for any specified position of the dependent variable:

data(longley)
lm( longley[,7] ~. , data = longley[,-7] )

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to