Function which runs lm over different variables
问题 I would like to create a function which can run a regression model (e.g. using lm) over different variables in a given dataset. In this function, I would specify as arguments the dataset I'm using, the dependent variable y and the independent variable x. I want this to be a function and not a loop as I would like to call the code in various places of my script. My naive function would look something like this: lmfun <- function(data, y, x) { lm(y ~ x, data = data) } This function obviously