-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData_Transformation.Rmd
64 lines (44 loc) · 1.33 KB
/
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
---
title: "Data_Transformation"
author: "Chenrui_Xiao"
date: "2024-10-31"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Define Data Transformation Function
A Data Transformation Function is defined below. It applies logarithmic transformation to the second column in a dataset.
```{r function_definition}
ln_trans <- function(data) {
#transform second column to ln_data
data[2] <- log(data[2])
return(data)
}
```
## Function Test
We can test the function using prssure, a built-in R dataset. It is a dataset that shows the relationship between pressure and temperature.
First, we plot the dataset.
```{r prssure}
plot(pressure)
```
Looks like it is suitable for ln_trans!
Now let's try the function and see how the plot changes.
```{r function test}
ln_pressure <- ln_trans(pressure)
plot(ln_pressure)
```
## Define New Data Transformation Function
A New Data Transformation Function is defined below. It applies square root transformation to the second column in a dataset.
```{r new function_definition}
sqrt_trans <- function(new_data) {
#transform second column to sqrt_data
new_data[2] <- sqrt(new_data[2])
return(new_data)
}
```
We can also test the new function with the pressure dataset.
```{r new function test}
sqrt_pressure <- sqrt_trans(pressure)
plot(sqrt_pressure)
```