Getting started

To work with R Markdown, if necessary:

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 code chunks and inline R code

The following document is mainly based on https://bookdown.org/yihui/rmarkdown/r-code.html.

You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I (Cmd + Option + I on macOS).

There are a lot of things you can do in a code chunk: you can produce text output, tables, or graphics. You have fine control over all these output via chunk options, which can be provided inside the curly braces (between ```{r and }).

The value of a chunk option can be an arbitrary R expression, which makes chunk options extremely flexible. For example, the chunk option eval controls whether to evaluate (execute) a code chunk, and you may conditionally evaluate a chunk via a variable defined previously, e.g.,

# execute code if the date is later than a specified day
do_it = Sys.Date() > '2018-02-14'
x = rnorm(10000)
x[1:5]
## [1] -2.0331336  1.0357938  0.5269961 -0.7879876  0.8870512
hist(x,55)

There are a large number of chunk options in knitr documented at https://yihui.name/knitr/options. We list a subset of them below:

Besides code chunks, you can also insert values of R objects inline in text. For example:

For a circle with the radius 15, its area is 706.8583471.

Writting LATEX

You can write LATEX code easily, e.g. \(y_{i}=\mathbf{x}_{i}^{\top}\mathbf{\beta}+\epsilon_{i}\), \(\epsilon_{i}\sim N(0,\sigma^{2})\).

\(\left(\int_{a}^{b} f(x) \; dx\right)\), \(\sum_{x = a}^{b} f(x)\), \(\prod_{x = a}^{b} f(x)\), \(\log(x)\), \(\exp(x)\)

Greek letters: \(\epsilon \varepsilon E\)

To write an equation \[\sum_{n=1}^{10} n^2\]