2

I am dealing with multiple files with variable number of columns i.e. each file in the dataset contains a different number of columns.

In each of the files, the first column is the output variable. The remaining columns are input variables for regression.

So, let us assume that we have a data frame D with the following columns:

output    abc  abd   dab   cdb ...

i.e. the name of the fields are also not fixed.

I wish to fit a linear regression model using lm in R, as follows

model <- lm(output ~ abc + abd + dab + cdb ...., data = D)

given that I will have to determine the formula expression using the field names, which I do not know beforehand.

How do I achieve this?

Indian
  • 977
  • 3
  • 12
  • 24

1 Answers1

3

You can do:

model <- lm(output ~ ., data = D)

The dot . will take into account all the rest fields.

George
  • 5,808
  • 15
  • 83
  • 160