with_groups {dplyr} | R Documentation |
Perform an operation with temporary groups
Description
This was an experimental function that allows you to modify the grouping
variables for a single operation; it is superseded in favour of using the
.by
argument to individual verbs.
Usage
with_groups(.data, .groups, .f, ...)
Arguments
.data |
A data frame |
.groups |
< Use |
.f |
Function to apply to regrouped data.
Supports purrr-style |
... |
Additional arguments passed on to |
Examples
df <- tibble(g = c(1, 1, 2, 2, 3), x = runif(5))
# Old
df %>%
with_groups(g, mutate, x_mean = mean(x))
# New
df %>% mutate(x_mean = mean(x), .by = g)
[Package dplyr version 1.1.4 Index]