dplyr
joinsRead R4DS chapter 13.
Solve chapters Joining Tables and Left and Right Joins of the Joining Data with dplyr in R course at DataCamp.
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.
Download a current version of Systembolaget’s assortment using Class_files/Systembolaget.R
and construct:
Class_files/systembolaget2019-10-30.csv
).Any particular types of beverages that has been added/removed?
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 x 8
## id identifier species_id height weight base_experience order
## <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 bulbasaur 1 7 69 64 1
## 2 2 ivysaur 2 10 130 142 2
## 3 3 venusaur 3 20 1000 236 3
## 4 4 charmander 4 6 85 62 5
## 5 5 charmeleon 5 11 190 142 6
## 6 6 charizard 6 17 905 240 7
## # … with 1 more variable: is_default <dbl>
(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 x 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 x 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 x 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