-
Notifications
You must be signed in to change notification settings - Fork 35
[FEAT] Equivalent to group_by(.drop = FALSE) in group_by() and group_by_vars() #775
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Currently, group_by() and group_by_vars() do not allow to compute groups, keeping levels that are not present in the dataset, something like what dplyr::group_by(.drop = FALSE) does.
Yet, using groups from group_by() into fsummarise() or converting them to a GRP object shows that {collapse} honors .drop = FALSE. So, I guess it could be added as an argument to group_by() and group_by_vars() (and GRP.default()) quite easily?
Reproducible example:
library(dplyr)
library(collapse)
iris2 <- iris[iris$Species != "versicolor", ]
# dplyr, do not drop unused factor levels
iris2 |>
group_by(Species, .drop = FALSE) |>
summarise(mean = mean(Sepal.Length))
# collapse... how to do the same with fgroup_by() or group_by_vars()?
iris2 |>
fgroup_by(Species) |>
fsummarise(mean = fmean(Sepal.Length))
# Yet, collapse is handling it correctly when using group_by():
iris2 |>
group_by(Species, .drop = FALSE) |>
fsummarise(mean = fmean(Sepal.Length))
# Indeed, conversion from grouped_df to GRP is considering .drop = FALSE
iris2 |>
group_by(Species, .drop = TRUE) |>
GRP()
iris2 |>
group_by(Species, .drop = FALSE) |>
GRP()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request