5.1 Writing Functions

5.1.1 Fahrenheit to Kelvin

\(k = ((f - 32) * (5 / 9)) + 273.15\)

((32 - 32) * (5 / 9)) + 273.15
## [1] 273.15
((212 - 32) * (5 / 9)) + 273.15
## [1] 373.15
((-42 - 32) * (5 / 9)) + 273.15
## [1] 232.0389
f_k <- function(f_temp) {
    ((f_temp - 32) * (5 / 9)) + 273.15
}
f_k(32)
## [1] 273.15
f_k(212)
## [1] 373.15
f_k(-42)
## [1] 232.0389

5.1.2 Kelvin to Celsius

k_c <- function(temp_k) {
    temp_c <- temp_k - 273.15
    return(temp_c)
}
k_c(0)
## [1] -273.15

5.1.3 Fahrenheit to Celsius

f_c <- function(temp_f) {
    temp_k <- f_k(temp_f)
    temp_c <- k_c(temp_k)
    return(temp_c)
}
f_c(32)
## [1] 0
f_c(212)
## [1] 100