Skip to content

Instantly share code, notes, and snippets.

@perlatex
Created May 12, 2020 10:47
Show Gist options
  • Save perlatex/9e334e97b8b80e25b5e7d7e908e7fec8 to your computer and use it in GitHub Desktop.
Save perlatex/9e334e97b8b80e25b5e7d7e908e7fec8 to your computer and use it in GitHub Desktop.
library(dplyr, warn.conflicts = FALSE)
mtcars %>%
group_nest(cyl) %>%
mutate(model = purrr::map(data, ~ lm(mpg ~ wt, data = .))) %>%
mutate(result = purrr::map(model, ~ broom::tidy(.))) %>%
tidyr::unnest(result)
mtcars %>%
group_by(cyl) %>%
group_modify(
~ broom::tidy(lm(mpg ~ wt, data = .))
)
mtcars %>%
nest_by(cyl) %>%
summarise(
broom::tidy(lm(mpg ~ wt, data = data))
)
mtcars %>%
group_by(cyl) %>%
summarise(
broom::tidy(lm(mpg ~ wt, data = cur_data()))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment