Import data

# excel file
data <- read_excel("../01_module4/data/myData.xlsx")
data
## # A tibble: 193 × 9
##    hdi_rank_2023 country           human_development_in…¹ life_expectancy_at_b…²
##            <dbl> <chr>                              <dbl>                  <dbl>
##  1             1 Iceland                            0.972                   82.7
##  2             2 Norway                             0.97                    83.3
##  3             2 Switzerland                        0.97                    84.0
##  4             4 Denmark                            0.962                   81.9
##  5             5 Germany                            0.959                   81.4
##  6             5 Sweden                             0.959                   83.3
##  7             7 Australia                          0.958                   83.9
##  8             8 Hong Kong, China…                  0.955                   85.5
##  9             8 Netherlands                        0.955                   82.2
## 10            10 Belgium                            0.951                   82.1
## # ℹ 183 more rows
## # ℹ abbreviated names: ¹​human_development_index_hdi, ²​life_expectancy_at_birth
## # ℹ 5 more variables: expected_years_of_schooling <dbl>,
## #   mean_years_of_schooling <dbl>, gross_national_income_gni_per_capita <dbl>,
## #   gni_per_capita_rank_minus_hdi_rank <dbl>, hdi_rank_2022 <chr>

Apply the following dplyr verbs to your data

Filter rows

filter(data, human_development_index_hdi >= 0.9)
## # A tibble: 37 × 9
##    hdi_rank_2023 country           human_development_in…¹ life_expectancy_at_b…²
##            <dbl> <chr>                              <dbl>                  <dbl>
##  1             1 Iceland                            0.972                   82.7
##  2             2 Norway                             0.97                    83.3
##  3             2 Switzerland                        0.97                    84.0
##  4             4 Denmark                            0.962                   81.9
##  5             5 Germany                            0.959                   81.4
##  6             5 Sweden                             0.959                   83.3
##  7             7 Australia                          0.958                   83.9
##  8             8 Hong Kong, China…                  0.955                   85.5
##  9             8 Netherlands                        0.955                   82.2
## 10            10 Belgium                            0.951                   82.1
## # ℹ 27 more rows
## # ℹ abbreviated names: ¹​human_development_index_hdi, ²​life_expectancy_at_birth
## # ℹ 5 more variables: expected_years_of_schooling <dbl>,
## #   mean_years_of_schooling <dbl>, gross_national_income_gni_per_capita <dbl>,
## #   gni_per_capita_rank_minus_hdi_rank <dbl>, hdi_rank_2022 <chr>

Arrange rows

arrange(data,desc( gross_national_income_gni_per_capita))
## # A tibble: 193 × 9
##    hdi_rank_2023 country           human_development_in…¹ life_expectancy_at_b…²
##            <dbl> <chr>                              <dbl>                  <dbl>
##  1            17 Liechtenstein                      0.938                   83.6
##  2             2 Norway                             0.97                    83.3
##  3            13 Singapore                          0.946                   83.7
##  4            43 Qatar                              0.886                   82.4
##  5            11 Ireland                            0.949                   82.4
##  6            25 Luxembourg                         0.922                   82.2
##  7             2 Switzerland                        0.97                    84.0
##  8             4 Denmark                            0.962                   81.9
##  9            60 Brunei Darussalam                  0.837                   75.3
## 10            17 United States                      0.938                   79.3
## # ℹ 183 more rows
## # ℹ abbreviated names: ¹​human_development_index_hdi, ²​life_expectancy_at_birth
## # ℹ 5 more variables: expected_years_of_schooling <dbl>,
## #   mean_years_of_schooling <dbl>, gross_national_income_gni_per_capita <dbl>,
## #   gni_per_capita_rank_minus_hdi_rank <dbl>, hdi_rank_2022 <chr>

Select columns

select(data, country, human_development_index_hdi, gross_national_income_gni_per_capita, life_expectancy_at_birth)
## # A tibble: 193 × 4
##    country  human_development_in…¹ gross_national_incom…² life_expectancy_at_b…³
##    <chr>                     <dbl>                  <dbl>                  <dbl>
##  1 Iceland                   0.972                 69117.                   82.7
##  2 Norway                    0.97                 112710.                   83.3
##  3 Switzer…                  0.97                  81949.                   84.0
##  4 Denmark                   0.962                 76008.                   81.9
##  5 Germany                   0.959                 64053.                   81.4
##  6 Sweden                    0.959                 66102.                   83.3
##  7 Austral…                  0.958                 58277.                   83.9
##  8 Hong Ko…                  0.955                 69436.                   85.5
##  9 Netherl…                  0.955                 68344.                   82.2
## 10 Belgium                   0.951                 63582.                   82.1
## # ℹ 183 more rows
## # ℹ abbreviated names: ¹​human_development_index_hdi,
## #   ²​gross_national_income_gni_per_capita, ³​life_expectancy_at_birth

Add columns

mutate(data,
       gni_rank = hdi_rank_2023 + gni_per_capita_rank_minus_hdi_rank) %>%
    
    select(hdi_rank_2023, country, gni_rank)
## # A tibble: 193 × 3
##    hdi_rank_2023 country                gni_rank
##            <dbl> <chr>                     <dbl>
##  1             1 Iceland                      13
##  2             2 Norway                        2
##  3             2 Switzerland                   7
##  4             4 Denmark                       8
##  5             5 Germany                      18
##  6             5 Sweden                       15
##  7             7 Australia                    21
##  8             8 Hong Kong, China (SAR)       12
##  9             8 Netherlands                  14
## 10            10 Belgium                      19
## # ℹ 183 more rows