A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/tidyverse/dplyr/issues/4723 below:

Broadly consider do() and rowwise() · Issue #4723 · tidyverse/dplyr · GitHub

With the idea of (finally!) coming up with a formal replacement.

Imaginary code:

gapminder %>%
  nest_by(country) %>% 
  mutate(fit = lm(lifeExp ~ year, data = data)) %>% 
  summarise(broom::tidy(fit))

Equivalent to:

library(gapminder)
library(tidyverse)

gapminder %>%
  group_by(country) %>%
  nest() %>% 
  mutate(
    fit = map(data, ~ lm(lifeExp ~ year, data = .x)),
    tidy = map(fit, broom::tidy)
  ) %>% 
  select(tidy) %>% 
  unnest(tidy)
#> Adding missing grouping variables: `country`
#> # A tibble: 284 x 6
#> # Groups:   country [142]
#>    country     term         estimate std.error statistic  p.value
#>    <fct>       <chr>           <dbl>     <dbl>     <dbl>    <dbl>
#>  1 Afghanistan (Intercept)  -508.     40.5        -12.5  1.93e- 7
#>  2 Afghanistan year            0.275   0.0205      13.5  9.84e- 8
#>  3 Albania     (Intercept)  -594.     65.7         -9.05 3.94e- 6
#>  4 Albania     year            0.335   0.0332      10.1  1.46e- 6
#>  5 Algeria     (Intercept) -1068.     43.8        -24.4  3.07e-10
#>  6 Algeria     year            0.569   0.0221      25.7  1.81e-10
#>  7 Angola      (Intercept)  -377.     46.6         -8.08 1.08e- 5
#>  8 Angola      year            0.209   0.0235       8.90 4.59e- 6
#>  9 Argentina   (Intercept)  -390.      9.68       -40.3  2.14e-12
#> 10 Argentina   year            0.232   0.00489     47.4  4.22e-13
#> # … with 274 more rows

Or

gapminder %>%
  group_by(country) %>%
  do(fit = lm(lifeExp ~ year, data = .)) %>% 
  do(data.frame(country = .$country, broom::tidy(.$fit)))

This requires:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4