group_by {poorman} | R Documentation |
Group by one or more variables
Description
Determine the groups within a data.frame
to perform operations on. ungroup()
removes the grouping levels.
Usage
group_by(.data, ..., .add = FALSE, .drop = group_by_drop_default(.data))
ungroup(x, ...)
Arguments
.data |
|
... |
One or more unquoted column names to group/ungroup the data by. |
.add |
|
.drop |
|
x |
A |
Value
When using group_by()
, a data.frame
, grouped by the grouping variables.
When using ungroup()
, a data.frame
.
Examples
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)
[Package poorman version 0.2.7 Index]