The link above is what you should explore to understand R Markdown.
Can replace ‘html_document’ with ‘pdf_document’ in the .Rmd (Rmarkdown) file above manually to generate the output in your preferred format. However, I would strongly suggest using HTML format initially as the setup is likely to reduce math symbol issues if you do not have Latex installed locally.
Also, make sure to change the settings of the document based on your preferences by clicking on the Setting symbol (next to Knit button) -> Output Options -> Include table of contents/Output Format…
This contains the link to R Markdown Cheatsheet. Please read it - it has everything you need to know about R Markdown for our course.
This is my first attempt - normal text.
This is my second attempt - bold.
This is my third attempt - italicize.
# Clear the workspace
rm(list = ls()) # Clear environment
gc() # Clear unused memory
## used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
## Ncells 521312 27.9 1154817 61.7 NA 669291 35.8
## Vcells 959786 7.4 8388608 64.0 16384 1839828 14.1
cat("\f") # Clear the console
par(mfrow=c(1,1)) # Clear plots. Can use dev.off()
Run a chunk with eval=FALSE now, thus no R output printed but commands still printed.
?factorial
factorial(5)
5*4*3*2*1
df<- 5
Note df object not created, as code chunk is skipped/not evaluated.
This is not the most important option.
?factorial
factorial(5)
## [1] 120
5*4*3*2*1
## [1] 120
factorial(0)
## [1] 1
?choose
choose(n = 3,k = 3) # combinations
## [1] 1
choose(3,0) # only 1 way to make this selection
## [1] 1
Run the same chunk above with echo=False. Make sure to change the r code chunk name if you simply copy-pasted the code chunk. We will run the factorial(5) command below.
## [1] 120
Can print graphs in your file too.
plot(iris[1:4], col=iris$Species)
Put the math symbols,or equations within $ math symbol here $ signs to generate -
\(X_1\) with $X_{1}$
\(X_{12}\)
\(\pi\) with $\pi$. See all Greek Symbols.
\(Y^{23}+X_{19}\) with $Y^{23}+X_{19}$
\(\frac{N}{D}\) with $\frac{N}{D}$
\(Prob(AB)=\frac{N}{D}\)
\(\bar x\) with $\bar x$
\(\hat y\) with $\hat y$
If the math Latex math symbols are not working/giving your errors even with HTML format, it could be due to you not being connected online. You could simply install Latex locally to avoid this issue.
Again, please read the R markdown cheat sheet for more features.
Use the Outline view, and Code Chunk view to navigate your document more effortlessly.
Do note that # have the same regular comment meaning in a code chunk, but a heading/subheading implication outside R code chunks in the .Rmd documents.
Not required, but may be worth a check for the future.