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:
convertTemp <- function(value, to="C") {
result <- switch(to,
C = (value - 32) * 5/9,
F = (value * 9/5) + 32,
K = value + 273.15,
"Unknown target temperature unit."
)
return(result)
}
convertTemp(100, "F")
## [1] 212
convertTemp(32, "C")
## [1] 0
convertTemp(0, "K")
## [1] 273.15
tempK <- convertTemp(40, "K")
sprintf("40°C is equivalent to %f°K", tempK)
## [1] "40°C is equivalent to 313.150000°K"
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.