rmarkdown
BasicsLab Goal: The goal of this lab is to introduce rmarkdown
! Afterwords you won’t be an expert, but you’ll have taken your first step into a larger world.
You should use the .Rmd
file which created this document as a template for the lab. This file can be found in the .zip
file that contains all the necessary files for the lab.
[Exercise] Write an unordered list of your classes this semester. Make the short course name (STAT 430) bold. Have the short course name link to the course description in the course explorer. Make the actual course title (Basics of Statistical Learning) italic.
[Exercise] Add a chunk to this document that sums the integers from 1
to 100
. It should display both the code and results after being knit. (Also, can you make this chunk only show output when knit? How about display the code, but don’t run the chunk when knit?)
[Exercise] Add a chunk to this document that sums the integers from 1
to 100
. It should display only the results after being knit.
[Exercise] Read in lab02-data.csv
as lab02_data
.
# your code here
[Exercise] Report the first 10 rows of lab02_data
as a table. Hint: check out the kable()
function from the knitr
packge.
# your code here
[Exercise] Create a scatterplot of dist
vs speed
for the cars
data, a dataset built into R
. Use chunk options to make the plot larger than the default.
# your code here
We probably went way too fast in lecture if this is your first time seeing rmarkdown
. However, even if we went a lot slower, you would still need to engage a lot with rmarkdown
to really get the hang of it. There are a number of things you should do to help get yourself up to speed:
solution
chunk option. This is not something you should use, this is just a by-product of the document creation method used.rmarkdown
.rnorm(10)
set.seed(42)
rnorm(10)
[Exercise] Repeatedly run the (entire) two previous chunks. What’s the difference?
With RMarkdown, you can not only mix R
and markdown
, but you can also use LaTeX. It can be used inline: \(y = x + 2\) or in “equation mode,”
\[ a^2 + b^2 = c^2 \]
[Exercise] Write the density function for a normal distribution using LaTeX in equation mode.
Some other things to try: