October 2019
Intermediate to advanced
316 pages
9h 45m
English
Using nested dataframes can be done with the following steps:
library(tidyr)library(dplyr)library(purrr)library(magrittr)library(ggplot2)nested_mt <- nest(mtcars, -cyl)
nested_mt_list_cols <- nested_mt %>% mutate( model = map(data, ~ lm(mpg ~ wt, data = .x)))
nested_mt_list_cols <- nested_mt_list_cols %>% mutate( tidy_model = map(model, tidy))
unnest(nested_mt_list_cols, tidy_model)
models_df <- nest(mtcars, -cyl) %>% mutate( model = map(data, ~ lm(mpg ~ wt, data = .x)), tidy_model = map(model, tidy) ) %>% unnest(tidy_model) ...
Read now
Unlock full access