Intro to R Markdown (rmd)

Stat210 Lab 1
September 4, 2017

Submitting your homework

  • Weekly assignments must be submitted as a printed copy of rmd
  • Due every Thursday in class
  • TAs are available for help!

What is R Markdown?

  • Rmd is a dynamic way to present your R scripts
  • You can show your R code and explain it
  • Basically, it's like combining Word, LaTex, and R
  • Great way to create a report

example

Rmd basics

You essentially need to do 3 things to make an rmd file.

  • Set up rmd
  • Write text
  • Write R code

1 Setting up the rmd

setup

  • If you open an rmd file in RStudio (File-New File-R Markdown), this should automatically be there
  • Please write your name, date, and title

2 Writing text

text

  • You can specify headers in rmd
  • One # indicates “Header 1”, two # is “Header 2”, which is slightly smaller than “Header 1”
  • Use * for italics and ** for bold
  • To type special symbols (eg. Greek letters), use $
  • Ex) $ \ sigma$ to type \( \sigma \)

3 Writing R code

code

  • Put ```{r} above your R code, and ```below to indicate you are writing R code
  • You can easily tell by the shaded area

Repeat 2 and 3!

How to render ("knitting")

knit

  • Click “Knit”
  • There are three options (HTML, PDF, Word)
  • Any of them are fine, but PDF and Word look better than HTML
  • To knit in PDF, you may need to install MikTex