hey can anyone explain `.groups = 'drop'`

.groups = 'drop' , its use / meaning

Check out the article here (specifically the summarise() section of Verbs)

Excerpting from the above article (though, again, it's worth just reading the relevant section in full):

Since version 1.0.0 the groups may also be kept (.groups = "keep") or dropped (.groups = "drop").

by_sex_gender %>% 
  summarise(n = n(), .groups = "keep") %>% 
  group_vars()
#> [1] "sex"    "gender"

by_sex_gender %>% 
  summarise(n = n(), .groups = "drop") %>% 
  group_vars()
#> character(0)

When the output no longer have grouping variables, it becomes ungrouped (i.e. a regular tibble).

1 Like

Thank you so much. Appreciate it alot.

Hi,
A few links with interesting comments, in the first you can find and I quote:
""bc Hadley wants it that way". :grinning:
https://stackoverflow.com/questions/48489219/why-does-summarize-drop-a-group

and more detailed explanation below:

and here as well:

best wishes,
Andrzej

I think I read, when dplyr 1.0 was released, that Hadley thought the default should have been drop in the first place. But they made the wrong call before.

does it have any practical meaning(have u faced any problems without it) , or is it just high level stuff and don't need to care?

I have issues with it when I try to use the summarised df and try to select a subset of columns. I then get a message saying that the grouped fields have been added back rather than just the subset.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.