[Solved] How to create a loop that will make regression models in R? [closed]
Here’s a solution without loops. # some artificial data set.seed(1) daf <- data.frame(species = factor(paste0(“species”, c(rep(1:3, 10)))), year = rep(2000:2009, 3), x = sample(1:100, 30)) library(dplyr) library(broom) lm_fit <- daf %>% group_by(species) %>% do(fit = lm(x ~ year, .)) tidy(lm_fit, fit) # or as.data.frame(tidy(lm_fit, fit)) to get a data.frame # # A tibble: 6 x … Read more