Now that we can separate data for each group(s), we can fit a model to each tibble in
map()from the purrr package (also
tidyverse). We’re going to add the results to our existing tibble using
mutate()from the dplyr package (again,
tidyverse). Here’s a generic version of our pipe with adjustable parts in caps:
Read the whole thing. Hat tip, R-Bloggers.