group_by | R Documentation |
Determine the groups within a data.frame
to perform operations on. ungroup()
removes the grouping levels.
group_by(.data, ..., .add = FALSE, .drop = group_by_drop_default(.data))
ungroup(x, ...)
.data |
|
... |
One or more unquoted column names to group/ungroup the data by. |
.add |
|
.drop |
|
x |
A |
When using group_by()
, a data.frame
, grouped by the grouping variables.
When using ungroup()
, a data.frame
.
group_by(mtcars, am, cyl)
ungroup(mutate(group_by(mtcars, am, cyl), sumMpg = sum(mpg)))
mtcars %>%
group_by(am, cyl) %>%
mutate(sumMpg = sum(mpg)) %>%
ungroup()
mtcars %>%
group_by(carb) %>%
filter(any(gear == 5))
# You can group by expressions: this is just short-hand for
# a mutate() followed by a group_by()
mtcars %>% group_by(vsam = vs + am)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.