These exercises cover the sections of Data wrangling with tidy.

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

 

Exercise 2

 

  1. Create a dataframe with a new variable that contains the rank of the length variable. Arrange this new data frame by IGF (lowest to highest).
  2. Create a dataframe with a new variable that is IGF/length. Arrange by this new variable (highest to lowest).

ANSWERS

Answer for Q1

## # A tibble: 97 x 6
##    salmon_id common_name    age_classbylength length_mm IGF1_ng_ml length_rank
##        <dbl> <chr>          <chr>                 <dbl>      <dbl>       <dbl>
##  1     35045 Steelhead      juvenile                177       4.46        49  
##  2     35081 Chinook salmon yearling                196       5.56        63.5
##  3     35062 Steelhead      juvenile                198       5.90        65.5
##  4     35138 Chinook salmon yearling                142       9.17        18  
##  5     35039 Steelhead      juvenile                201       9.92        70  
##  6     35135 Chinook salmon yearling                181      11.5         52.5
##  7     35113 Chinook salmon yearling                162      14.2         38  
##  8     35064 Steelhead      juvenile                225      16.0         80.5
##  9     35082 Chinook salmon yearling                150      17.1         29.5
## 10     35057 Steelhead      juvenile                240      20.2         86  
## # … with 87 more rows

Answer for Q2

## # A tibble: 97 x 6
##    salmon_id common_name    age_classbylength length_mm IGF1_ng_ml IGF_perlength
##        <dbl> <chr>          <chr>                 <dbl>      <dbl>         <dbl>
##  1     35055 Steelhead      juvenile                123       55.7         0.453
##  2     35087 Coho salmon    yearling                164       73.6         0.449
##  3     35142 Chinook salmon yearling                149       66.5         0.446
##  4     35112 Chinook salmon yearling                205       90.5         0.442
##  5     35092 Chinook salmon yearling                192       81.8         0.426
##  6     35117 Chinook salmon yearling                147       61.2         0.416
##  7     35090 Chinook salmon yearling                167       67.3         0.403
##  8     35143 Chinook salmon yearling                204       80.9         0.397
##  9     35059 Steelhead      juvenile                185       73.1         0.395
## 10     35101 Steelhead      juvenile                167       65.4         0.392
## # … with 87 more rows