Skip to content
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

Group by aggregate dynamic column name matching #2619

Closed
zx8754 opened this issue Apr 5, 2017 · 4 comments
Closed

Group by aggregate dynamic column name matching #2619

zx8754 opened this issue Apr 5, 2017 · 4 comments

Comments

@zx8754
Copy link

zx8754 commented Apr 5, 2017

Instead of below:

df1 %>% 
  group_by(Sepal.Length, Sepal.Width) %>% 
  summarise(mySum = sum(Petal.Length))

I want to be able to do this:

df1 %>% 
  group_by(starts_with("Sepal")) %>% 
  summarise(mySum = sum(Petal.Length))

Reproducible data and code at StackOverflow.

Version: dplyr_0.5.0; R version 3.3.2 (2016-10-31)

@lionel-
Copy link
Member

lionel- commented Apr 5, 2017

This will be x %>% group_by_at(vars(starts_with("Sepal"))) in the next version.

@lionel- lionel- closed this as completed Apr 5, 2017
@zx8754
Copy link
Author

zx8754 commented Apr 5, 2017

Phew that was quick, thank you @lionel- !

OK, this was essentially duplicate of issue #2053 and #2613

@zx8754
Copy link
Author

zx8754 commented Apr 5, 2017

@lionel- Maybe I am asking for impossible (not familiar with internals of dplyr), but would it not be better to make group_by accept column indices, instead of creating a new function group_by_at?

@lionel-
Copy link
Member

lionel- commented Apr 5, 2017

no, group_by() has mutate semantics, so you can do stuff like group_by(mtcars, as.factor(cyl))

@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants