I have 50 predictors in my dataset, I would like to get the second order terms and the second order interaction terms of these predictors.
Take the mtcars data set in R
This is almost surely a bad idea. Anyway, using the mtcars data set, after removing categorical variables
mtcars=mtcars[,1:7] lm(as.formula(paste0("mpg~.^2+",paste0("poly(",colnames(mtcars),",2)",collapse="+"))) ,data=mtcars)