I try to run a several regressions on a selected part of a data frame. There are 22 columns. One is "DATE", one is "INDEX" and S1, S2, S3 ... S20.
I run the regression this way:
Regression <- lm(as.matrix(df[c('S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'S16', 'S17', 'S18', 'S19', 'S20')]) ~ df$INDEX)
Regression$coefficients
1) How can I make the code shorter? Just like using an interval to tell R: take columns S1 to S20 as explanatory variables and run the regression on them with the dependent variable INDEX.
2) Regression Formula is: a + b*INDEX + error Then extract all the "b" estimates from the regression. Lets say the columns have 10 rows, so there must be 10 estimates. Also extract all the errors: that must be 10 errors in each column, and a total of 10*20=200 errors in total.
Since I have no experience with R, all kind of help is welcome! Thank you!