This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
convTemp <- function(val, to = "K_C") {
# Apply conversion based on 'to' value
mult <- switch(to,
K_C = (val - 273.15),
K_F = ((val - 273.15) * (9/5) + 32),
C_K = (val + 273.15),
C_F = (val * (9/5) + 32),
F_C = ((val - 32) * (5/9)),
F_K = ((val - 32) * (5/9) + 273.15))
# Check if the conversion result is valid
if (is.na(mult)) {
print("Invalid Combination")
} else {
return(mult)
}
}
# Testing the function
convTemp(23, "K_F") # Convert 23 Celsius to Fahrenheit
## [1] -418.27
convTemp(200, "C_K") # Convert 200 Celsius to Kelvin
## [1] 473.15
convTemp(90, "F_C") # Convert 90 Fahrenheit to Celsius
## [1] 32.22222
You can also embed plots, for example:
Note that the echo = FALSE
parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.