---
title: "Penguin data wrangling"
author: "Team ASTA"
output: html_document
---

## Introduction

The aim of this exercise is to practice your data-wrangling skills using the penguins dataset.

In particular you should illustrate the use of both functions for numerical summaries of data such as `favstats()` and functions for subsetting and manipulating data such as `select()`, `filter()`, and `arrange()`.

First we load the relevant packages (notice `message=FALSE` in the chunk option to avoid a lot of uninteresting messages when loading the packages):
```{r message=FALSE}
library(mosaic)
```

Then we save the data with a shorter name:
```{r}
pingviner <- palmerpenguins::penguins
```

## Numerical summaries of data

- Use `favstats()` to display numerical summaries of penguin mass for each species.

- Can you find the smallest and largest penguin mass for each island without using `favstats()`?

## Subsetting data

This command makes a new dataset `big_flipper_female` of female penguins with a flipper length above a certain threshold:
```{r}
big_flipper_female <- pingviner %>% filter(sex == "female" & flipper_length_mm>200)
```

Try to make similar subsets of data yourself to answer questions you may ask yourself. E.g:

- Can you find all male penguins observed in 2007? 
- What was the mean body mass of male penguins for each island in 2007?
- What was it in 2009?

- Can you make a dataset only containing the mass and sex of `Adelie` penguins disregarding all other columns?
  (Hint: Use both `select()` and `filter()`)
- Can you arrange the data above such that the penguins with lowest mass are at the top of the table? (Hint: Use `arrange()`)
  + Some penguins have the same body mass. Use arrange in the same way as above, but such that ties are broken by also arranging after bill length and bill depth.
- How many female `Adelie` penguins have a body mass above 4 kg on each island? (Hint: Have a look at `n` in `favstats()` output.)
