+ - 0:00:00
Notes for current slide
Notes for next slide

Data wrangling

Aggregation

Ben Baumer

SDS 192
Sep 30, 2020
(http://beanumber.github.io/sds192/lectures/mdsr_wrangling_04-group_by.html)

1 / 7

2 / 7

The Five Verbs

The Five Verbs

  • select()

  • filter()

  • mutate()

  • arrange()

  • summarize()

Plus:

  • group_by()

  • rename()

  • inner_join()

  • left_join()

3 / 7

summarize(): collapse into a single row

4 / 7

group_by(): group by a variable

5 / 7

Summary funs

  • take a vector

  • output a single value

6 / 7

Example: average fuel economy

mtcars %>%
group_by(cyl) %>%
summarize(
num_cars = n(),
avg_mpg = mean(mpg)
)
## `summarise()` ungrouping output (override with `.groups` argument)
## # A tibble: 3 x 3
## cyl num_cars avg_mpg
## <dbl> <int> <dbl>
## 1 4 11 26.7
## 2 6 7 19.7
## 3 8 14 15.1
7 / 7

2 / 7
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow