This works beautifully! You know I did not know how many columns in advance
either. So this method is very good.

Many thanks!




On 10/7/06, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
>
> Try this:
>
>
> run.lm <- function(DF, response = names(DF)[1], fo = y~.) {
>        fo[[2]] <- as.name(response)
>        eval(substitute(lm(fo, DF)))
> }
>
> # test
> run.lm(iris)
> run.lm(iris, "Sepal.Width")
>
>
> Another possibility is to rename the first column:
>
> On 10/7/06, HelponR <suncertain@gmail.com> wrote:
> > Hello!
> >
> > I am trying to use lm to do a simple regression but on a batch of
> > different files.
> >
> > Each file has different column names.
> >
> > I know the first column is the dependent variable and all the rest are
> > explanatory variables.
> >
> > The column names are in the first line of the file.
> >
> > But it seems lm() requires I know the variable names in advance?
> >
> > Is there a way to dynamically read in variable names and send to lm()?
> >
> > Many many thanks!!!
> >
> >
> > Urania
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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
> > and provide commented, minimal, self-contained, reproducible code.
> >
>

	[[alternative HTML version deleted]]

