![](../hanze/hanze.png)

---

[Go back to the main page](../index.html)  
[Go back to the R overview page](../R/R_01_index.html)  

---

```{r setup, include=FALSE} 
knitr::opts_chunk$set(warning = FALSE, message = FALSE) 
```

# R: Data Import


## Data Import Exercises

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

This file can be downloaded [here](./R_04_data_import_exercises.Rmd).


### Exercise 1

First, check the following files in your text editor (NotePad for Windows users, TextEdit for Apple users). 

- [file 1](./files_04_data_import_exercises/exercise01/fish_data_1.csv)  
- [file 2](./files_04_data_import_exercises/exercise01/fish_data_2.csv)  
- [file 3](./files_04_data_import_exercises/exercise01/fish_data_3.csv)  
- [file 4](./files_04_data_import_exercises/exercise01/fish_data_4.csv)  

Next, report the field separator and the function that you will use to import the data. Also think of you need extra arguments in your function to import the data correctly (for example: do you need the `locale =` argument?).
Last, load the datasets in R using the csv, csv2, or tsv import functionality and check if the data is imported correctly.

File 1:
```{r}
#Your code here for file 1
```

File 2:
```{r}
#Your code here for file 2
```

File3:
```{r}
#Your code here for file 3
```

File 4:
```{r}
#Your code here for file 4
```


### Exercise 2

Download the [Heart Disease Health Indicators](https://www.kaggle.com/datasets/alexteboul/heart-disease-health-indicators-dataset) dataset to your computer.
Unzip the file and import the csv data in R.

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


### Exercise 3

Download the [Properties of ATC-accepted medicines](https://www.kaggle.com/datasets/tonibois/properties-of-atc-accepted-medicines) dataset to your computer.
Unzip the file and import the csv data in R.

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


### Exercise 4

Download the [Food allergens and allergies](https://www.kaggle.com/datasets/boltcutters/food-allergens-and-allergies) dataset to your computer.
Unzip the file and import the csv data in R.

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


### Exercise 5

Download the [Patients](https://www.kaggle.com/datasets/ouzkoca/patients) dataset to your computer.
Unzip the file and import the csv data in R.

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


### Exercise 6

Use R to create a csv file from the following table:

|Protein Name |Location       |Weight (kD)|Date submission |Source       |
|:------------|--------------:|----------:|---------------:|------------:|
| ORF1        | 21571..25392  | 14.3      | 29-FEB-2020    | Published   |
| ORF3a       | 25401..26228  | 23.9      | 29-FEB-2020    | Unpublished |
| ORF4b       | 26253..26480  | 161.1     | 29-FEB-2020    | Unpublished |
| ORF6        | 27210..27395  | 35.9      | 29-FEB-2020    | Submitted   |
| ORF7a       | 27402..27767  | 24.6      | 29-FEB-2020    | Unpublished |


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

Use code to prove that the data was written to a csv file (code to read the csv file that you have just created):

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

### Exercise 7

Use the same data from exercise 6 but now write code to create an Excel file. Make sure to include the column headers.

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


### Exercise 8

Use code to open the Excel file from exercise 7.

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


### Exercise 9

The zip file in [this link](./files_04_data_import_exercises/exercise09/read_data_empty.zip) contains 25 small exercises to load data as a tibble in R.  
Unpack the zip file and open the Rmd file for instructions.  

---

[Go back to the main page](../index.html)  
[Go back to the R overview page](../R/R_01_index.html)  
<a href="#top">⬆️ Back to Top</a>  

---


>This web page is distributed under the terms of the Creative Commons Attribution License which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.
>Creative Commons License: CC BY-SA 4.0.

