The summarize verb

Introduzione al Tidyverse

David Robinson

Chief Data Scientist, DataCamp

Data transformation and visualization

Introduzione al Tidyverse

Extracting data

gapminder %>%
  filter(country == "United States", year == 2007)
# A tibble: 1 x 6
        country continent  year lifeExp       pop gdpPercap
          <fct>     <fct> <int>   <dbl>     <dbl>     <dbl>
1 United States  Americas  2007  78.242 301139947  42951.65
Introduzione al Tidyverse

The summarize verb

gapminder %>%
  summarize(meanLifeExp = mean(lifeExp))
# A tibble: 1 x 1
  meanLifeExp
        <dbl>
1    59.47444
Introduzione al Tidyverse

Summarizing one year

gapminder %>%
  filter(year == 2007) %>%
  summarize(meanLifeExp = mean(lifeExp))
# A tibble: 1 x 1
  meanLifeExp
        <dbl>
1    67.00742
Introduzione al Tidyverse

Summarizing into multiple columns

gapminder %>%
  filter(year == 2007) %>%
  summarize(meanLifeExp = mean(lifeExp),
            totalPop = sum(pop))
# A tibble: 1 x 2
  meanLifeExp   totalPop
        <dbl>      <dbl>
1    67.00742 6251013179
Introduzione al Tidyverse

Functions you can use for summarizing

  • mean
  • sum
  • median
  • min
  • max
Introduzione al Tidyverse

Let's practice!

Introduzione al Tidyverse

Preparing Video For Download...