R Markdown Example: 5 10 15 20 25 Speed
R Markdown Example: 5 10 15 20 25 Speed
Introduction
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. You can
install Markdown like you would any other R package. However, for Markdown to work correctly, you will need
to download and install a LaTex distribution. For Mac users, you can obtain the appropriation distribution,
MacTeX, at https://tug.org/mactex/downloading.html. For Windows, go to http://miktex.org/download.
Note that the 64-bit option is below the standard 32-bit option.
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:
summary(cars)
##
##
##
##
##
##
##
speed
Min.
: 4.0
1st Qu.:12.0
Median :15.0
Mean
:15.4
3rd Qu.:19.0
Max.
:25.0
dist
Min.
: 2.00
1st Qu.: 26.00
Median : 36.00
Mean
: 42.98
3rd Qu.: 56.00
Max.
:120.00
60
0
20
40
dist
80
100 120
10
15
20
25
speed
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that
generated the plot.
Equations in Markdown
You can also render equations using Markdown. Here is a simple example:
n
1X
xi
n i=1
Note that in the Markdown environment (and in Latex generally), the character is used for superscripts
and the underscore character is used for subscripts. Also, a $ sign on each end of an equation will produce an
inline equation, which can be put anywhere, even in the middle of a sentence. A double $$ will produce a
centered equation like the one we see above. But if we wanted to, for example, refer to a rejection threshold
(\alpha), we can just put the single $ around the appropriate LaTex expression.
The braces are used to group elements together inside a single operator. So, note that we use the braces to
enclose i = 1 because we want all of that to go inside the subscript under the sum. When you have only a
single character after an operator (e.g. the i after x_), you dont need the braces. However, it is in general
good practice to always mark off pieces of your equations with the braces as it will reduce errors and make
the code more intelligible.
For those just starting out in Markdown, the Latex math symbols will require some learning, especially
because the Greek symbols we often use for parameters will be unfamiliar to you. The Detexify website
at http://detexify.kirelabs.org/classify.html will help with this. It lets you draw the symbol you want to
use, and will then return to you the LaTex command for that symbol. The entire math symbols sheet can
be found at http://estudijas.lu.lv/pluginfile.php/14809/mod_page/content/16/instrukcijas/matematika_
moodle/LaTeX_Symbols.pdf.
You can also use text inside the math environment, and you can modify this text in various ways. Common
modifiers is the bold modifier, which produces bolded expressions such as this B (\mathbf{B}) and the
caligraphic modifer, which produces caligraphic letters like this Z (\mathcal{Z}) from one of Professor
Olivellas lecture slides.
Other Resources
Markdown has several excellent resources. Check out the excellent reference guide at https://www.rstudio.
com/wp-content/uploads/2015/03/rmarkdown-reference.pdf and the cheat sheet at https://www.rstudio.
com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf. Note the use of the hashtags will prevent you
from making annotations in a Markdown document unless you are inside an code chunk, where the behavior
of all special characters is exactly the same as it is in a basic R Script document.