Do this before class

Read R4DS chapter 13.

Solve chapters Joining Tables and Left and Right Joins of the Joining Data with dplyr in R course at DataCamp.

To do during class

More dental care

During last class you worked with records of adults visiting dental care

dental_data <- read_csv2("class_files/Statistikdatabasen_2019-11-14 23_25_40.csv", skip = 1, n_max = 580)

join this with class_files/BE0101A5.csv obtained from SCB, containing population numbers, and compute number of visits per capita.

Pokemon

Pokemon comes in various types, e.g. fire-, water- and grass-type, which affects their strengths and weaknesses in battle. Some are of dual-type.

A table of Pokemon can be loaded by

library(tidyverse)
pokemon <- read_csv("https://raw.githubusercontent.com/veekun/pokedex/master/pokedex/data/csv/pokemon.csv")
head(pokemon)
## # A tibble: 6 × 8
##      id identifier species_id height weight base_experience order is_default
##   <dbl> <chr>           <dbl>  <dbl>  <dbl>           <dbl> <dbl>      <dbl>
## 1     1 bulbasaur           1      7     69              64     1          1
## 2     2 ivysaur             2     10    130             142     2          1
## 3     3 venusaur            3     20   1000             263     3          1
## 4     4 charmander          4      6     85              62     5          1
## 5     5 charmeleon          5     11    190             142     6          1
## 6     6 charizard           6     17    905             267     7          1

(Mac-users may need the Curl-package in order to read directly from an https-address), a table of types by

types <- read_csv("https://raw.githubusercontent.com/veekun/pokedex/master/pokedex/data/csv/types.csv")
head(types)
## # A tibble: 6 × 4
##      id identifier generation_id damage_class_id
##   <dbl> <chr>              <dbl>           <dbl>
## 1     1 normal                 1               2
## 2     2 fighting               1               2
## 3     3 flying                 1               2
## 4     4 poison                 1               2
## 5     5 ground                 1               2
## 6     6 rock                   1               2

and finally a table linking pokemon to type by

pokemon_types <- read_csv("https://raw.githubusercontent.com/veekun/pokedex/master/pokedex/data/csv/pokemon_types.csv")
head(pokemon_types)
## # A tibble: 6 × 3
##   pokemon_id type_id  slot
##        <dbl>   <dbl> <dbl>
## 1          1      12     1
## 2          1       4     2
## 3          2      12     1
## 4          2       4     2
## 5          3      12     1
## 6          3       4     2

We can e.g. see that Pokemon no 1 (bulbasaur) is of type 12 (grass) and type 4 (poison). Join the tables, aiming for a full table like poke_table below and investigate how height or weight depends on type.

head(poke_table)
## # A tibble: 6 × 6
##   pokemon_id identifier slot1 slot2  height weight
##        <dbl> <chr>      <chr> <chr>   <dbl>  <dbl>
## 1          1 bulbasaur  grass poison      7     69
## 2          2 ivysaur    grass poison     10    130
## 3          3 venusaur   grass poison     20   1000
## 4          4 charmander fire  <NA>        6     85
## 5          5 charmeleon fire  <NA>       11    190
## 6          6 charizard  fire  flying     17    905

Bulbasaur (Image source: Pokémon Wiki - Fandom)