Import data

# excel file
data <- read_excel("../00_data/myData_charts.xlsx")
data
## # A tibble: 21 × 10
##     year host     winner second third fourth goals_scored teams games attendance
##    <dbl> <chr>    <chr>  <chr>  <chr> <chr>         <dbl> <dbl> <dbl>      <dbl>
##  1  1930 Uruguay  Urugu… Argen… USA   Yugos…           70    13    18     434000
##  2  1934 Italy    Italy  Czech… Germ… Austr…           70    16    17     395000
##  3  1938 France   Italy  Hunga… Braz… Sweden           84    15    18     483000
##  4  1950 Brazil   Urugu… Brazil Swed… Spain            88    13    22    1337000
##  5  1954 Switzer… West … Hunga… Aust… Urugu…          140    16    26     943000
##  6  1958 Sweden   Brazil Sweden Fran… West …          126    16    35     868000
##  7  1962 Chile    Brazil Czech… Chile Yugos…           89    16    32     776000
##  8  1966 England  Engla… West … Port… Sovie…           89    16    32    1614677
##  9  1970 Mexico   Brazil Italy  West… Urugu…           95    16    32    1673975
## 10  1974 Germany  West … Nethe… Pola… Brazil           97    16    38    1774022
## # ℹ 11 more rows

Apply the following dplyr verbs to your data

Filter rows

Arrange rows

arrange(data, desc(attendance))
## # A tibble: 21 × 10
##     year host     winner second third fourth goals_scored teams games attendance
##    <dbl> <chr>    <chr>  <chr>  <chr> <chr>         <dbl> <dbl> <dbl>      <dbl>
##  1  1994 USA      Brazil Italy  Swed… Bulga…          141    24    52    3568567
##  2  2014 Brazil   Germa… Argen… Neth… Brazil          171    32    64    3441450
##  3  2006 Germany  Italy  France Germ… Portu…          147    32    64    3367000
##  4  2018 Russia   France Croat… Belg… Engla…          169    32    64    3031768
##  5  1998 France   France Brazil Croa… Nethe…          171    32    64    2859234
##  6  2002 Japan, … Brazil Germa… Turk… South…          161    32    64    2724604
##  7  1990 Italy    West … Argen… Italy Engla…          115    24    52    2527348
##  8  1986 Mexico   Argen… West … Fran… Belgi…          132    24    52    2407431
##  9  2010 South A… Spain  Nethe… Germ… Urugu…          145    32    64    2167984
## 10  1982 Spain    Italy  West … Pola… France          146    24    52    1856277
## # ℹ 11 more rows

Select columns

select(data, attendance:games)
## # A tibble: 21 × 2
##    attendance games
##         <dbl> <dbl>
##  1     434000    18
##  2     395000    17
##  3     483000    18
##  4    1337000    22
##  5     943000    26
##  6     868000    35
##  7     776000    32
##  8    1614677    32
##  9    1673975    32
## 10    1774022    38
## # ℹ 11 more rows

Add columns

mutate(data, attendance = games + teams)
## # A tibble: 21 × 10
##     year host     winner second third fourth goals_scored teams games attendance
##    <dbl> <chr>    <chr>  <chr>  <chr> <chr>         <dbl> <dbl> <dbl>      <dbl>
##  1  1930 Uruguay  Urugu… Argen… USA   Yugos…           70    13    18         31
##  2  1934 Italy    Italy  Czech… Germ… Austr…           70    16    17         33
##  3  1938 France   Italy  Hunga… Braz… Sweden           84    15    18         33
##  4  1950 Brazil   Urugu… Brazil Swed… Spain            88    13    22         35
##  5  1954 Switzer… West … Hunga… Aust… Urugu…          140    16    26         42
##  6  1958 Sweden   Brazil Sweden Fran… West …          126    16    35         51
##  7  1962 Chile    Brazil Czech… Chile Yugos…           89    16    32         48
##  8  1966 England  Engla… West … Port… Sovie…           89    16    32         48
##  9  1970 Mexico   Brazil Italy  West… Urugu…           95    16    32         48
## 10  1974 Germany  West … Nethe… Pola… Brazil           97    16    38         54
## # ℹ 11 more rows

Summarize by groups