Chapter 16 R Markdown
You can use R Markdown to
- save and execute code
- generate pdfs (like the lecture notes)
- generate html files (like the website for the lecture notes)
- make slides for presentations
Installation: follow the instruction on https://bookdown.org/yihui/rmarkdown/installation.html
Use ctrl + shift + k to knit your file (or click the Knit button in RStudio)
Some References:
R for Data Science: https://r4ds.had.co.nz/r-markdown.html
R Cookbook: https://rc2e.com/rmarkdown
R Markdown Cookbook: https://bookdown.org/yihui/rmarkdown-cookbook/
The files for generating the notes and assignments (onQ -> R Markdown Examples)
You may use R Markdown for your final project.
16.1 Basic formatting
# Level 1 Heading
## Level 2 Heading
### Level 3 Heading
#### Level 4 Heading
##### Level 5 Heading
###### Level 6 Heading
16.4 List
To create a bulleted list, start each line with an asterisk (*) like so:
* first item
* second item
* third item
Results:
- first item
- second item
- third item
To create a numbered list, start each line with 1. as follows:
1. first item
1. second item
1. third item
Results:
- first item
- second item
- third item
1. first item
1. second item
a. subitem 1
a. subitem 2
i. sub-subitem 1
i. sub-subitem 2
a. subitem 2
1. third item
Results:
- first item
- second item
- subitem 1
- subitem 2
- sub-subitem 1
- sub-subitem 2
- subitem 2
- third item
16.5 Table
||$H_0$ is true|$H_1$ is true|
|--|-----|----|
|Reject $H_0$| Type I error | No Error|
|Do not reject $H_0$| No Error | Type II Error|
Results:
\(H_0\) is true | \(H_1\) is true | |
---|---|---|
Reject \(H_0\) | Type I error | No Error |
Do not reject \(H_0\) | No Error | Type II Error |
16.6 R code
Two ways: inline and code chunk.
Code Chunk:
Inline: The square root of x
is 2.4494897.
Controlling Which Code and Results Are Shown
16.8 Latex Equation
R Markdown supports the LaTeX math equation notation.
Reference: https://en.wikibooks.org/wiki/LaTeX/Mathematics
Inline: \(x + 2\)
Displayed Equation:
\[\begin{equation*} x + 2 = 4 \end{equation*}\]