Learn R Programming

poorman (version 0.2.3)

group_by: 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)

ungroup(x, ...)

Arguments

.data

data.frame. The data to group.

...

One or more unquoted column names to group/ungroup the data by.

.add

logical(1). When FALSE (the default) group_by() will override existing groups. To add to existing groups, use .add = TRUE.

x

A data.frame.

Value

When using group_by(), a data.frame, grouped by the grouping variables.

When using ungroup(), a data.frame.

Examples

Run this code
# NOT RUN {
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))

# }

Run the code above in your browser using DataLab