Closed romainfrancois closed 5 years ago
i.e. a mutate that is only allowed to overwrite factors.
Is it possible to leave the original levels as is and trim only the grouping structure on calculation? IMHO, what the users want is probably not that fine-grained control over factors by an extra function, but something that can be done within group_by()
like this (and TRUE
by default for backward-compatibility):
g <- iris %>%
filter(Species == "setosa") %>%
group_by(Species, .trim = TRUE)
In this case, grouped_df
should remember the decision whether to drop empty groups or not so that it can decide automatically when it gets regrouped later (I expect regrouping will frequently happen if the default of .preserve
is FALSE
).
Is it possible to leave the original levels as is and trim only the grouping structure on calculation?
This is essentially the previous behaviour. Unless I don't understand what you mean. But the contract with the new dplyr is that if there is a level, it is represented. That's something we feel strongly about.
I don't think an argument to group_by()
is visually strong enough.
Ah, oh... Sorry, I terribly misunderstood how the new dplyr works. I thought the (edit: I'm confused, sorry...)groups
attribute is the master table of the groups and all verbs would work based on that information. Really sorry for the noise....
This will be much simpler than ⬆️ and more 💪 will be added to group_by()
in #4029
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
When we do this:
we still end up with 3 groups because we need to respect the levels. Previous versions would only give one group.
group_trim()
would be about giving the ability to re-model the factors.group_trim(<tidyselect spec>)
where the tidyselect spec would only apply to the grouping variables, e.g.perhaps we'd need variants with
_all
and_at
(_if
does not make much sense)This is essentially a 4 steps
Is dropping the only thing we want or would it make sense to have something to
lump
too ?, or should it be more of a mutate type interface, e.g.