-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_data_transformation.rmd
73 lines (52 loc) · 1.99 KB
/
01_data_transformation.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
title: '01_data_transformation'
output: html_document
---
```{r setup, include=FALSE}
# Setting echo to TRUE such that the code is shown in the knitted document.
knitr::opts_chunk$set(echo = TRUE)
```
### Loading the Iris Dataset and defining a function
The aim of this function is to remove any missing data that may be present in the dataset.
```{r}
# Defining a function with a single argument called data, that takes the dataset
# and performs some input transformation on it.
# Loading the built-in iris dataset in R.
data(iris)
# Creating a function that removes any rows that have missing values values in them.
remove_nas <- function(data) {
clean_data <- na.omit(data)
return(clean_data)
}
remove_nas(iris)
```
### Second function initially created in the dev branch
```{r}
# Creating a function that creates a new column called Sepal.Area, which
# multiplies their length and width.
sepal_area <- function(data_new) {
data_new$Sepal.Area <- data_new$Sepal.Width * data_new$Sepal.Length
return(data_new)
}
# Applying this function to the iris dataset.
transformed_data <- sepal_area(iris)
head(transformed_data)
```
### Code used to create GitHub repository
The code below is not set to run, it is solely present for informative purposes
about the commands that were used to create this repository.
```{bash, eval = FALSE}
# Due to the eval = FALSE argument, this code will not be run when knitting the document.
# It is solely informative for the purposes of this assessment.
# Setting the working directory.
cd ls
cd Desktop/Local
# Using the link that is accessible on the Repository page, after creating a new repository online.
git clone https://github.com/50280/MY472_Formative_Ex1.git
# Creating a new RMarkdown file using the touch function
# Named this 01_data_transformation. If the workflow were to be continued,
# this title format would allow to keep files in order.
touch 01_data_transformation.rmd
# Checking that the file was implemented as intended.
ls
```