Say I have a data frame with a bunch of columns. I need to call lm function over the column 1 and 2, 1 and 3, and so on. So basically I need to loop over all columns and store the results of the fit as I build the model. The problem I am running into is that:
lm(df[1]~df[2], data = df) #doesnt work. In this case df is the data frame object
#and df[1] is the first column.
What is a good way to do this in a loop, as in access the columns of df in an iterative fashion?
here is an example of the first column of
dfregressed as the dependent variable against all other columns which i think is what you want..If you were more specific about the coefficients/output you want then this answer could be better