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?