-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2021S QF202 Recitation 1.Rmd
82 lines (56 loc) · 3.18 KB
/
2021S QF202 Recitation 1.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
title: "2021S QF202 Recitation 1"
output: pdf_document
urlcolor: blue
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Installation
0. Install R https://cran.rstudio.com/
1. Install RStudio https://rstudio.com/products/rstudio/download/
2. Install LaTeX https://www.latex-project.org/get/
# Create Your First R Markdown File
## R Markdown
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:
```{r cars, include=FALSE}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo = FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
# Including Equations
You can also type equations using LaTeX syntax, for example:
$$dS_t=\mu S_tdt+\sigma S_tdW_t$$
\begin{align*}
\log(S_{t})&=\log \left(S_{0}\exp \left(\left(\mu -{\frac {\sigma ^{2}}{2}}\right)t+\sigma W_{t}\right)\right)\\
&=\log(S_{0})+\left(\mu -{\frac {\sigma ^{2}}{2}}\right)t+\sigma W_{t}
\end{align*}
# Code Chunks
Reference: https://rmarkdown.rstudio.com/lesson-3.html
## Insert Chunk
You can quickly insert chunks like these into your file with
* the keyboard shortcut **Ctrl + Alt + I** (OS X: **Cmd + Option + I**)
* the Add Chunk command in the editor toolbar
or by typing the chunk delimiters ` ```{r} ` and ` ``` `.
When you render your .Rmd file, R Markdown will run each code chunk and embed the results beneath the code chunk in your final report.
## Chunk Options
Chunk output can be customized with [knitr options](https://yihui.org/knitr/options/), arguments set in the `{}` of a chunk header. Above, we use five arguments:
1. `include = FALSE` prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks.
1. `echo = FALSE` prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures.
1. `message = FALSE` prevents messages that are generated by code from appearing in the finished file.
1. `warning = FALSE` prevents warnings that are generated by code from appearing in the finished.
1. `fig.cap = "..."` adds a caption to graphical results.
See the [*R Markdown Reference Guide*](https://rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf) for a complete list of knitr chunk options.
## Global Options
To set global options that apply to every chunk in your file, call `knitr::opts_chunk$set` in a code chunk. Knitr will treat each option that you pass to `knitr::opts_chunk$set` as a global default that can be overwritten in individual chunk headers.
# A Quick Introduction to `sample` Function
See .R file
We can include R output in PDF file generated by R Markdown.
```{r}
rbinom(1000,size=100,prob=0.8)
```