```{r setup}
library(tidyverse)
```

## Exercise 01

Load and preprocess _band-adaptation.csv_:

1. Read it (try specifying the URL instead of the local filename).Do not forget to specify column types!
2. compute proportion of "same" responses as a using `Nsame` (number of "same" responses) and `Ntotal` (total number of trials).
3. Convert `Prime` and `Probe` column to factors with the order "Sphere", "Quadro", "Dual", "Single".
4. Compute [median](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/median.html) and [median absolute deviation from the median](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/mad.html) for `Psame` for all combinations of `Prime` and `Probe`.

This should be a _single_ pipe that requires no intermediate temporary variables!

```{r exercise-01}
```

## Exercise 02

Using table from exercise 01, compute a new column with "<median> ± <MAD>" using `glue()`. You will want to use [round()](https://stat.ethz.ch/R-manual/R-devel/library/base/html/Round.html) function to restrict values to just 2 digit after the decimal point. Pivot table so that there is one `Prime` per row and one `Probe` per column.

```{r exercise-02}
```

## Exercise 03
Repeat exercise 02 but using `paste()` or `paste0()`

```{r exercise-03}
```

## Exercise 04
Repeat exercise 02 but using `sprintf()`. Do not use `round()`, instead use formatting flags to ensure only 2 digits after a decimal point.

```{r exercise-04}
```

## Exercise 05
Read all files from `persistence` subfolder (extract data from `persistence.zip` into a subfolder first) using `purrr::map_dfr()` and `read_csv()` (remember to specify column types). Rename columns `Shape1` to `Prime` and `Shape2` to `Probe`. Use [separate()](https://tidyr.tidyverse.org/reference/separate.html) to preprocess [persistence](data/persistence.zip) data and create two new columns for hour and minutes from `Session` column.

```{r exercise-05}
```

## Exercise 06
Using same [persistence](data/persistence.csv) data extract birth year and gender of participants from `Participant` code but keep the code column. Convert year to a number and gender into a factor type with better labels.

```{r exercise-06}
```

## Exercise 07
Repeat exercise 6 but use [
substr()](https://stat.ethz.ch/R-manual/R-patched/library/base/html/substr.html) to extract each column (`BirthYear` and `Gender`) from the participant code.

```{r exercise-07}
```

## Exercise 08
Repeat exercise 7 but using [str_sub()](https://stringr.tidyverse.org/reference/str_sub.html) function.

```{r exercise-08}
```

## Exercise 09
Using table from previous exercise,  use a regular expression to [filter()](https://dplyr.tidyverse.org/reference/filter.html) out Primes and Probes that _end_ with a _single_ digit. The regular expression pattern must specify that only one digit is allowed and that it must be the last symbol. Use grepl() function for this task.

```{r exercise-09-1}
```

Repeat the exercise but using str_detect() function.
```{r exercise-09-2}
```

## Exercise 10
Using table from previous exercise, extract participants' unique code, the first three letters of `Participant` column. The pattern must match one or more upper case letters at the beginning of the string.

```{r exercise-10}
```

## Exercise 11
Using same table, use sub() function to anonymize the birth year of our participants. Replace the _four_ digits that represent their birth year with a _single_ `"-"`.

```{r exercise-11-1}
```

Repeat the exercise but using str_replace() function.
```{r exercise-11-2}
```

## Exercise 12
Using the same table, match and replace any _single_ digit with "-". Do it using base R function

```{r exercise-12-1}
```

Repeat the exercise but using stringr library function.
```{r exercise-12-2}
```
