These exercises cover the sections of Data wrangling with tidy.
All files can be found in the “dataset” directory.
# Create a dataframe of the variables _age_ and _IGF_ of only the _Steelhead_ fish
df1_A <- filter(df1, common_name == 'Steelhead')
select(df1_A, age_classbylength, IGF1_ng_ml)
## # A tibble: 38 x 2
## age_classbylength IGF1_ng_ml
## <chr> <dbl>
## 1 juvenile 42.7
## 2 juvenile NA
## 3 juvenile 24.2
## 4 juvenile NA
## 5 juvenile 63.5
## 6 juvenile 61.2
## 7 juvenile 30.6
## 8 juvenile 49.4
## 9 juvenile 56.3
## 10 juvenile 55.7
## # … with 28 more rows
# Create a dataframe of all variables but the _IGF_ values, for all fish that begin with _S_
df1_A <- filter(df1, str_starts(common_name,'S'))
select(df1_A, -IGF1_ng_ml)
## # A tibble: 49 x 4
## salmon_id common_name age_classbylength length_mm
## <dbl> <chr> <chr> <dbl>
## 1 35035 Sockeye salmon juvenile 121
## 2 35036 Sockeye salmon juvenile 112
## 3 35037 Steelhead juvenile 220
## 4 35038 Steelhead juvenile 152
## 5 35034 Sockeye salmon juvenile 139
## 6 35048 Steelhead juvenile 288
## 7 35049 Steelhead juvenile 190
## 8 35050 Steelhead juvenile 283
## 9 35051 Steelhead juvenile 279
## 10 35052 Steelhead juvenile 235
## # … with 39 more rows