6.2 If else statements


k_c <- function(temp_k) {
    if (temp_k < 0) {
        warning('you passed in a negative Kelvin number')
        # stop()
        return(NA)
    } else {
        temp_c <- temp_k - 273.15
        return(temp_c)
    }
}
k_c(-9)
## Warning in k_c(-9): you passed in a negative Kelvin number
## [1] NA

Our current function does not deal with missing numbers

k_c(NA)
k_c(0)
## [1] -273.15