If you’re in a situation where you have a lot of parameters and want to run regressions on many subsets of a dataset based on those parameters, one option is to pmap:
library(purrr)library(broom)library(dplyr)# Example list of parameters to use as subsetscategories <- mtcars |>as_tibble() |>distinct(am)# Run the regressionpmap_dfr(categories, function(am) {# Subset data df <- mtcars |>as_tibble() |>filter(am ==!!am)# Run regression reg <-lm(mpg ~ hp, df)# Tidy outputtidy(reg)}, .id ="regression")