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

Expand data frame for all combinations of values for all variables without explicitly specifying variables names #704

mattwarkentin opened this issue Aug 7, 2019 · 1 comment


Copy link

@mattwarkentin mattwarkentin commented Aug 7, 2019


I posted the following question on Twitter:

I can’t seem to figure out how to use expand to get all combinations of values for all variables in df without specifying each var name explicitly? It’s easy with expand.grid. tibble(x=1:3, y=1:3) %>% expand.grid(). Can I tell expand() to use all vars?

@hadley asked if I would file an issue so he could think about it some more.

I suppose the Tweet is self-explanatory, I want to be able to expand a data frame for all possible combinations of values for every variable, without having to specify variable names explicitly.

This works:

tibble(x = 1:3, y = 1:3) %>% expand.grid()

This doesn't:

tibble(x = 1:3, y = 1:3) %>% expand()

Of course, in the two variable setting, explicitly typing tibble(x = 1:3, y = 1:3) %>% expand(x, y) is not a problem, but it doesn't scale well.

Something like this might be a possible solution:

tibble(x = 1:3, y = 1:3) %>% expand(vars(everything()))

This comment has been minimized.

Copy link

@hadley hadley commented Sep 7, 2019

You can use tibble(x = 1:3, y = 1:3) %>% expand_grid() in the dev version.

In the future, we'll support df %>% expand(something(everything()) but that'll come to dplyr first (and requires a little thought).

@hadley hadley closed this Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.