[R] First Variable in lm
Christian Hoffmann
christian.hoffmann at wsl.ch
Wed Mar 24 16:50:54 CET 2004
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)
}
What kind of function do I have to take instead of the
whateverthefirstofthevariablenamesis,
eval(), substitute(), get(), ...
to correctly compute this regression?
With lm(get(names(dat)[1] ~., data=dat) there are no errors, but the
first variable also shows up among the regressors.
Thanks for help.
Christian Hoffmann
--
Dr.sc.math.Christian W. Hoffmann,
http://www.wsl.ch/staff/christian.hoffmann
Mathematics + Statistical Computing e-mail: christian.hoffmann at wsl.ch
Swiss Federal Research Institute WSL Tel: ++41-44-73922- -77 (office)
CH-8903 Birmensdorf, Switzerland -11(exchange), -15 (fax)
More information about the R-help
mailing list