## Exercise 1: abalone

```{r, echo = FALSE, message = FALSE}
source(here::here("scripts/setup.R"))
```

Let's first load a dataset:

```{r, echo = TRUE}
abalone <- read_csv(file = here::here("data/abalone.csv"))
```

### Wrangling

1. Extract a tibble `length_sex_ring` which contains the `sex`, `diameter`,
   `height` and `rings` columns. The dataset should be filtered for
   length strictly larger than 0.6 and be sorted by increasing `sex` and
   decreasing `ring`.

   To check your answer:

   The output of `print(length_sex_ring, n = 5)` is

   ```
   # A tibble: 1,216 x 4
     sex   diameter height rings
     <chr>    <dbl>  <dbl> <dbl>
   1 F        0.585  0.185    29
   2 F        0.49   0.215    25
   3 F        0.54   0.215    24
   4 F        0.47   0.2      23
   5 F        0.52   0.225    23
   # … with 1,211 more rows
   ```
   
   ```{r}
   ## Your code goes here
   ```

2. Extract a tibble `count_prop` of dimension 3 x 3,
   which contains the `sex`, `count` and `prop` columns.
   The dataset should be grouped by increasing `sex` with counted numbers
   of each group. Then calculate the proportion of each count.

   To check your answer:

   The output of `print(count_prop, n = 5)` is

   ```
   # A tibble: 3 x 3
     sex   count  prop
     <chr> <int> <dbl>
   1 F      1307 0.313
   2 I      1342 0.321
   3 M      1528 0.366
   ```
   
   ```{r}
   ## Your code goes here
   ```

3. Extract a tibble `mean_max_min` of dimension 3 x 4, which contains the
   `sex`, `weight_mean`, `weight_max` and `weight_min` columns.
   The dataset should be grouped by increasing `sex` and summarized by
   finding mean, max and min of `shucked_weight`.

   To check your answer:

   The output of `print(mean_max_min, n = 5)` is

   ```
   # A tibble: 3 x 4
     sex   weight_mean weight_max weight_min
     <chr>       <dbl>      <dbl>      <dbl>
   1 F           0.446      1.49      0.031
   2 I           0.191      0.774     0.001
   3 M           0.433      1.35      0.0065
   ```
   
   ```{r}
   ## Your code goes here
   ```
   
4. Extract a tibble `filter_na` of dimension 2963 x 10,
   which contains all columns. The dataset should be filtered for diameter
   equal to `NA` or strictly greater than 0.36. The column `X` should be
   renamed as `index` and you should also reorder the columns such that
   `index`, `sex`, `length`, `diameter` and `rings` come first and then
   the other columns appear in their original order.

   To check your answer:

   The output of `print(filter_na, n = 5)` is

   ```
   # A tibble: 2,938 x 10
     index sex   length diameter rings height whole_weight shucked_weight
     <dbl> <chr>  <dbl>    <dbl> <dbl>  <dbl>        <dbl>          <dbl>
   1     1 M      0.455    0.365    15  0.095        0.514          0.224
   2     3 F      0.53     0.42      9  0.135        0.677          0.256
   3     4 M      0.44     0.365    10  0.125        0.516          0.216
   4     7 F      0.53     0.415    20  0.15         0.778          0.237
   5     8 F      0.545    0.425    16  0.125        0.768          0.294
   # … with 2,933 more rows, and 2 more variables: viscera_weight <dbl>,
   #   shell_weight <dbl>
   ```
   
   ```{r}
   ## Your code goes here
   ```
   
5. Extract a tibble `transmute_abalone` of dimension 4177 x 2,
   which contains the `whole_weight_in_mg` and `water_weight_in_mg` columns,
   corresponding respectively to the whole weight and water weight in
   milligrams.

   To check your answer:

   The output of `print(transmute_abalone, n = 5)` is

   ```
   # A tibble: 4,177 x 2
     whole_weight_in_mg water_weight_in_mg
                  <dbl>              <dbl>
   1               514               38.5
   2               226.               7.50
   3               677               69.
   4               516               31.5
   5               205               21.0
   # … with 4,172 more rows
   ```
   
   ```{r}
   ## Your code goes here
   ```
   
6. Extract a tibble `first_1000_rank` of dimension 1000 x 3,
   which contains the `diameter`, `rings` and `rings_rank` columns, sorted
   by ascending `rings_rank`, which is a column containing the rank
   corresponding to the value of the `rings` variable.
   Then, select the three columns and rank on the `rings` and
   filter for the rows corresponding to the first 1000 `rings_rank`.

   To check your answer:

   The output of `print(first_1000_rank, n = 5)` is

   ```
   # A tibble: 1,000 x 3
     diameter rings rings_rank
        <dbl> <dbl>      <int>
   1    0.055     1          1
   2    0.1       2          2
   3    0.1       3          3
   4    0.09      3          4
   5    0.12      3          5
   # … with 995 more rows
   ```
   
   ```{r}
   ## Your code goes here
   ```
   
7. Extract a tibble `n_distinct_rings_by_sex` of dimension 3 x 2,
   which contains the `sex` and `distinct_rings` columns.
   The dataset should be grouped by `sex` and then summarized to
   count distinct rings in each group.

   To check your answer:

   The output of `print(n_distinct_rings_by_sex, n = 5)` is

   ```
   # A tibble: 3 x 2
     sex   distinct_rings
     <chr>          <int>
   1 F                 23
   2 I                 21
   3 M                 24
   ```
   
   ```{r}
   ## Your code goes here
   ```
  
### Visualization

8. Draw a density plot of `rings`, colored by `sex`.
  
   ```{r}
   ## Your code goes here
   ```
  
9. Draw a histogram of the `diameter` with `binwidth` as 0.05,
   filled and faceted by `sex`.
  
   ```{r}
   ## Your code goes here
   ```
  
10. Draw a boxplot of `diameter` against `sex`.
   The ordering of boxes from left to right should be in descending order
   of the median `diameter` per group.
  
   ```{r}
   ## Your code goes here
   ```
  
11. Draw a point plot of `diameter` against `rings` with a smooth curve
   obtained using the `loess` method, and faceted by `sex`.
  
   ```{r}
   ## Your code goes here
   ```
  
12. Draw a violin plot of `whole_weight` against `length` faceted by `sex`.

   ```{r}
   ## Your code goes here
   ```
  