Description Usage Arguments Examples
This is an experimental new function that allows you to modify the grouping variables for a single operation.
1 | with_groups(.data, .groups, .f, ...)
|
.data |
A data frame |
.groups |
< Use |
.f |
Function to apply to regrouped data.
Supports purrr-style |
... |
Additional arguments passed on to |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | df <- tibble(g = c(1, 1, 2, 2, 3), x = runif(5))
df %>%
with_groups(g, mutate, x_mean = mean(x))
df %>%
with_groups(g, ~ mutate(.x, x1 = first(x)))
df %>%
group_by(g) %>%
with_groups(NULL, mutate, x_mean = mean(x))
# NB: grouping can't be restored if you remove the grouping variables
df %>%
group_by(g) %>%
with_groups(NULL, mutate, g = NULL)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.