-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broadly consider do() and rowwise() #4723
Comments
if we don't need library(gapminder)
library(dplyr, warn.conflicts = FALSE)
gapminder %>%
filter(continent == "Asia") %>%
group_by(country) %>%
summarise(broom::tidy(lm(lifeExp ~ year)))
#> # A tibble: 66 x 6
#> 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 Bahrain (Intercept) -860. 54.3 -15.8 2.07e- 8
#> 4 Bahrain year 0.468 0.0274 17.0 1.02e- 8
#> 5 Bangladesh (Intercept) -936. 32.3 -29.0 5.63e-11
#> 6 Bangladesh year 0.498 0.0163 30.5 3.37e-11
#> 7 Cambodia (Intercept) -736. 186. -3.95 2.74e- 3
#> 8 Cambodia year 0.396 0.0942 4.20 1.82e- 3
#> 9 China (Intercept) -989. 128. -7.74 1.57e- 5
#> 10 China year 0.531 0.0645 8.23 9.21e- 6
#> # … with 56 more rows Created on 2020-01-09 by the reprex package (v0.3.0.9000) |
If we were to :
Then we can have this: library(gapminder)
library(dplyr, warn.conflicts = FALSE)
gapminder %>%
filter(continent == "Asia") %>%
group_by(country) %>%
summarise(
fit = lm(lifeExp ~ year),
results = broom::tidy(fit)
) Perhaps with a warning here because we magic enlist a data frame (so a vector) of size > 1. And we could make it explicit with This loses some functionality that |
With the idea of (finally!) coming up with a formal replacement.
Imaginary code:
Equivalent to:
Or
This requires:
mutate.rowwise()
needs to automatically wrap in outputs in list where needed.rowwise()
needs to be able to capture grouping variables; orgrouped_df
needs some way to activate row-wise magic?summarise.rowwise()
would returngrouped_df
since might no longer have 1 row per group?nest_by()
that works likegroup_nest()
+rowwise()
. Needs a lot of thinking about name.The text was updated successfully, but these errors were encountered: