Import data

# csv file


# excel file
data <- read_excel("data/myData.xlsx")

Apply the following dplyr verbs to your data

Filter rows

filter(data, type_1 == "grass", type_2 == "poison")
## # A tibble: 15 × 23
##    Column1    id pokemon  species_id height weight base_experience type_1 type_2
##      <dbl> <dbl> <chr>         <dbl>  <dbl>  <dbl>           <dbl> <chr>  <chr> 
##  1       1     1 bulbasa…          1    0.7    6.9              64 grass  poison
##  2       2     2 ivysaur           2    1     13               142 grass  poison
##  3       3     3 venusaur          3    2    100               236 grass  poison
##  4      43    43 oddish           43    0.5    5.4              64 grass  poison
##  5      44    44 gloom            44    0.8    8.6             138 grass  poison
##  6      45    45 vileplu…         45    1.2   18.6             221 grass  poison
##  7      69    69 bellspr…         69    0.7    4                60 grass  poison
##  8      70    70 weepinb…         70    1      6.4             137 grass  poison
##  9      71    71 victree…         71    1.7   15.5             221 grass  poison
## 10     315   315 roselia         315    0.3    2               140 grass  poison
## 11     406   406 budew           406    0.2    1.2              56 grass  poison
## 12     407   407 roserade        407    0.9   14.5             232 grass  poison
## 13     590   590 foongus         590    0.2    1                59 grass  poison
## 14     591   591 amoongu…        591    0.6   10.5             162 grass  poison
## 15     835 10033 venusau…          3    2.4  156.              281 grass  poison
## # ℹ 14 more variables: hp <dbl>, attack <dbl>, defense <dbl>,
## #   special_attack <dbl>, special_defense <dbl>, speed <dbl>, color_1 <chr>,
## #   color_2 <chr>, color_f <chr>, egg_group_1 <chr>, egg_group_2 <chr>,
## #   url_icon <chr>, generation_id <dbl>, url_image <chr>

Arrange rows

arrange(data, desc(height))
## # A tibble: 949 × 23
##    Column1    id pokemon  species_id height weight base_experience type_1 type_2
##      <dbl> <dbl> <chr>         <dbl>  <dbl>  <dbl>           <dbl> <chr>  <chr> 
##  1     321   321 wailord         321   14.5  398               175 water  NA    
##  2     916 10114 exeggut…        103   10.9  416.              186 grass  dragon
##  3     881 10079 rayquaz…        384   10.8  392               351 dragon flying
##  4     874 10072 steelix…        208   10.5  740               214 steel  ground
##  5     879 10077 kyogre-…        382    9.8  430               347 water  NA    
##  6     208   208 steelix         208    9.2  400               179 steel  ground
##  7     797   797 celeste…        797    9.2 1000.              114 steel  flying
##  8      95    95 onix             95    8.8  210                77 rock   ground
##  9     929 10127 wishiwa…        746    8.2   78.6             217 water  NA    
## 10     384   384 rayquaza        384    7    206.              306 dragon flying
## # ℹ 939 more rows
## # ℹ 14 more variables: hp <dbl>, attack <dbl>, defense <dbl>,
## #   special_attack <dbl>, special_defense <dbl>, speed <dbl>, color_1 <chr>,
## #   color_2 <chr>, color_f <chr>, egg_group_1 <chr>, egg_group_2 <chr>,
## #   url_icon <chr>, generation_id <dbl>, url_image <chr>

Select columns

select(data, pokemon:weight)
## # A tibble: 949 × 4
##    pokemon    species_id height weight
##    <chr>           <dbl>  <dbl>  <dbl>
##  1 bulbasaur           1    0.7    6.9
##  2 ivysaur             2    1     13  
##  3 venusaur            3    2    100  
##  4 charmander          4    0.6    8.5
##  5 charmeleon          5    1.1   19  
##  6 charizard           6    1.7   90.5
##  7 squirtle            7    0.5    9  
##  8 wartortle           8    1     22.5
##  9 blastoise           9    1.6   85.5
## 10 caterpie           10    0.3    2.9
## # ℹ 939 more rows

Add columns

mutate(data,
       estimated_body_mass = height * weight) %>%
    select(height, weight, estimated_body_mass)
## # A tibble: 949 × 3
##    height weight estimated_body_mass
##     <dbl>  <dbl>               <dbl>
##  1    0.7    6.9                4.83
##  2    1     13                 13   
##  3    2    100                200   
##  4    0.6    8.5                5.1 
##  5    1.1   19                 20.9 
##  6    1.7   90.5              154.  
##  7    0.5    9                  4.5 
##  8    1     22.5               22.5 
##  9    1.6   85.5              137.  
## 10    0.3    2.9                0.87
## # ℹ 939 more rows

Summarize by groups

data %>%
    group_by(type_1) %>%
    summarise(
        avg_height = mean(height, na.rm =TRUE),
        avg_weight = mean(weight, na.rm = TRUE)
    )
## # A tibble: 18 × 3
##    type_1   avg_height avg_weight
##    <chr>         <dbl>      <dbl>
##  1 bug           0.937       35.8
##  2 dark          1.22        65.8
##  3 dragon        2.37       140. 
##  4 electric      0.851       28.5
##  5 fairy         0.763       22.4
##  6 fighting      1.19        56.6
##  7 fire          1.19        68.6
##  8 flying        1.23        54.8
##  9 ghost         1.22        66.1
## 10 grass         1.12        42.3
## 11 ground        1.30       147. 
## 12 ice           1.17        98.3
## 13 normal        1.04        45.0
## 14 poison        1.16        35.7
## 15 psychic       1.2         62.3
## 16 rock          1.09        82.1
## 17 steel         2.13       226. 
## 18 water         1.46        57.4