Use lapply for multiple regression with formula changing, not the dataset

前端 未结 4 1200
别那么骄傲
别那么骄傲 2020-12-18 09:35

I have seen an example of list apply (lapply) that works nicely to take a list of data objects, and return a list of regression output, which we can pass to Stargazer for n

4条回答
  •  天涯浪人
    2020-12-18 09:38

    You can also use get():

    # make a list of independent variables
      list_x <- list("nox","crim")
    
    # create regression function
      my_reg <- function(x) { lm(indus ~ get(x), data = Boston) }
    
    # run regression
      results <- lapply(list_x, my_reg)
    

提交回复
热议问题