These exercises cover the sections of Data wrangling with tidy.

All files can be found in the “dataset” directory.

 

Exercise 4

 

  1. Filter to only look at yearling in variable age_classbylength
  2. Group by common_name
  3. Create new variable that is z-score of length across groups
  4. Create boxplot of grouped length zscores

ANSWERS

Answer for Q1

## # A tibble: 44 x 5
##    salmon_id common_name    age_classbylength length_mm IGF1_ng_ml
##        <dbl> <chr>          <chr>                 <dbl>      <dbl>
##  1     35032 Chinook salmon yearling                147      41.3 
##  2     35142 Chinook salmon yearling                149      66.5 
##  3     35143 Chinook salmon yearling                204      80.9 
##  4     35145 Chinook salmon yearling                130      23.4 
##  5     35076 Chinook salmon yearling                173      52.9 
##  6     35077 Chinook salmon yearling                145      39.4 
##  7     35078 Chinook salmon yearling                152      52.8 
##  8     35079 Chinook salmon yearling                199      53.2 
##  9     35080 Chinook salmon yearling                145      46.2 
## 10     35081 Chinook salmon yearling                196       5.56
## # … with 34 more rows

Answer for Q2

## # A tibble: 44 x 5
## # Groups:   common_name [2]
##    salmon_id common_name    age_classbylength length_mm IGF1_ng_ml
##        <dbl> <chr>          <chr>                 <dbl>      <dbl>
##  1     35032 Chinook salmon yearling                147      41.3 
##  2     35142 Chinook salmon yearling                149      66.5 
##  3     35143 Chinook salmon yearling                204      80.9 
##  4     35145 Chinook salmon yearling                130      23.4 
##  5     35076 Chinook salmon yearling                173      52.9 
##  6     35077 Chinook salmon yearling                145      39.4 
##  7     35078 Chinook salmon yearling                152      52.8 
##  8     35079 Chinook salmon yearling                199      53.2 
##  9     35080 Chinook salmon yearling                145      46.2 
## 10     35081 Chinook salmon yearling                196       5.56
## # … with 34 more rows

Answer for Q3

## # A tibble: 44 x 6
## # Groups:   common_name [2]
##    salmon_id common_name    age_classbylength length_mm IGF1_ng_ml length_zscore
##        <dbl> <chr>          <chr>                 <dbl>      <dbl>         <dbl>
##  1     35032 Chinook salmon yearling                147      41.3         -0.810
##  2     35142 Chinook salmon yearling                149      66.5         -0.729
##  3     35143 Chinook salmon yearling                204      80.9          1.51 
##  4     35145 Chinook salmon yearling                130      23.4         -1.50 
##  5     35076 Chinook salmon yearling                173      52.9          0.247
##  6     35077 Chinook salmon yearling                145      39.4         -0.892
##  7     35078 Chinook salmon yearling                152      52.8         -0.607
##  8     35079 Chinook salmon yearling                199      53.2          1.30 
##  9     35080 Chinook salmon yearling                145      46.2         -0.892
## 10     35081 Chinook salmon yearling                196       5.56         1.18 
## # … with 34 more rows