How to add all variables its second degree in lm()? [duplicate]
问题 This question already has an answer here : R:fit dynamic number of explanatory variable into polynomial regression (1 answer) Closed 3 years ago . I have a dataframe with 16 variables. When I do multiple linear regression I do the following: fit <- lm(y ~ .,data=data) Now, I know how to add a second degree term of one of the variables: fit2 <- lm(y ~ poly(x1,2) + .,data=data) But now I don't want to write this out for all of my 16 variables. How can I do this in an easy way for all my