-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctiontest.Rmd
More file actions
105 lines (70 loc) · 1.45 KB
/
functiontest.Rmd
File metadata and controls
105 lines (70 loc) · 1.45 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
title: "functiontest"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(myTools)
```
# Work with some data in degrees
```{r}
environment_info("yay")
```
* CONVERT FROM f TO CELSIUS
* wRITE A FUNCTION
* WRITE A FUNCTIONS FROM c TO f
* dOCUMENT FUNCTION
```{r}
source('convert.R')
airtemps <- c(212, 100, 32, 64, 0, -20)
celsius1 <- (airtemps[1]-32)*5/9
celsius2 <- (airtemps[2]-32)*5/9
celsius3 <- (airtemps[3]-32)*5/9
celsius4 <- (airtemps[4]-32)*5/9
celsius5 <- (airtemps[5]-32)*5/9
celsius6 <- (airtemps[6]-32)*5/9
# or
celsius_all <- (airtemps-32)*5/9
new_fahr_to_celsius(airtemps)
```
# no wwrite a function to do it
```{r}
fahr_to_celsius <- function(fahr) {
celsius <- (fahr-32)*5/9
return(celsius)
}
celsius_temps=fahr_to_celsius(airtemps)
celsius_temps
```
## can define defualt values if the input is missing
```{r}
fahr_to_celsius <- function(fahr=212) {
celsius <- (fahr-32)*5/9
return(celsius)
}
fahr_to_celsius()
```
# New function to go in revserse
```{r}
celsius_to_fahr <- function(cels) {
fahr <- (cels*9/5)+32
return(fahr)
}
celsius_to_fahr(100)
```
```{r}
celsius_to_fahr(celsius_temps)
```
# Documenting functions
```{r}
#' converts temperate in Degrees Fahrenheit to Celsius
#'
#' @param fahr for the input value (degrees)
#' @return the converted value in Celsius
fahr_to_celsius <- function(fahr) {
celsius <- (fahr-32)*5/9
return(celsius)
}
```