I have a data set (mydata) with 1000 records (rows) and 20 variables (columns, x1....x20). The first column is my response variable (y). All data is numeric with no missing values.
This works fine:
fit <- y ~ x2 + x3 + ..... x20, data = mydata); summary(fit)
I am trying to figure out how to avoid typing in all the variable names (i.e. x1 + x2 + x3 etc).
I've tried:
predictors <- mydata[2:20]
fit <- lm(y ~ mydata[ c(2:20) ] # as well as mydata[2:20] and predictors
Error - invalid type (list) for variable 'predictors'.
Is there a way around this? Thank you for any assistance.