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

Bug? only .keep = "used" drops groups after mutate() #5582

Closed
courtiol opened this issue Nov 1, 2020 · 0 comments
Closed

Bug? only .keep = "used" drops groups after mutate() #5582

courtiol opened this issue Nov 1, 2020 · 0 comments

Comments

@courtiol
Copy link
Contributor

courtiol commented Nov 1, 2020

Setting .keep = "used" in mutate() is the only settings for this argument that induces the drop of the grouping in both devel and CRAN versions.

library(dplyr, warn.conflicts = FALSE)

iris %>%
  group_by(Species) %>%
  mutate(meanPL = mean(Petal.Length), .keep = "none")
#> # A tibble: 150 x 2
#> # Groups:   Species [3]
#>    Species meanPL
#>    <fct>    <dbl>
#>  1 setosa    1.46
#>  2 setosa    1.46
#>  3 setosa    1.46
#>  4 setosa    1.46
#>  5 setosa    1.46
#>  6 setosa    1.46
#>  7 setosa    1.46
#>  8 setosa    1.46
#>  9 setosa    1.46
#> 10 setosa    1.46
#> # … with 140 more rows

iris %>%
  group_by(Species) %>%
  mutate(meanPL = mean(Petal.Length), .keep = "used")
#> # A tibble: 150 x 2
#>    Petal.Length meanPL
#>           <dbl>  <dbl>
#>  1          1.4   1.46
#>  2          1.4   1.46
#>  3          1.3   1.46
#>  4          1.5   1.46
#>  5          1.4   1.46
#>  6          1.7   1.46
#>  7          1.4   1.46
#>  8          1.5   1.46
#>  9          1.4   1.46
#> 10          1.5   1.46
#> # … with 140 more rows

packageVersion("dplyr")
#> [1] '1.0.2.9000'

Created on 2020-11-01 by the reprex package (v0.3.0)

@courtiol courtiol changed the title Bug? only .keep = "used" in mutate drop groups Bug? only .keep = "used" drops groups after mutate() Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant