问题 I have an x-matrix of 8 columns. I want to run glmnet to do a lasso regression. I know I need to call: glmnet(x, y, family = "binomial", ...). However, how do I get x to consider all one way interactions as well? Do I have to manually remake the data frame: if so, is there an easier way? I suppose I was hoping to do something using an R formula. 回答1: Yes, there is a convenient way for that. Two steps in it are important. library(glmnet) # Sample data data <- data.frame(matrix(rnorm(9 * 10),