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:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

this is a tutorial of how to use R markdown for reproducible research

here we can writer without using hastags.

first ww will use tooth growth dataset.

to run R code on markdown we need to denote the desired section considered R code. we call this sections ” code chunks

Toothdata <- ToothGrowth

head(Toothdata)
##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5

we can run just one chunk using the play button.

fit<-lm(len~dose,data=ToothGrowth)

b<-fit$coefficients

plot(len~ dose, data=ToothGrowth)

abline(lm(len~ dose, data=ToothGrowth))
guinea pig tooth growth

guinea pig tooth growth

the slope of the regresion line is 9.7635714 # section headers

we can also put sections and subsections in our r markdown file, similar to numbers or bullet points in a word document. this is done with the # that we previusly used to denote text in an r script.

first level header

second level header

third level header

make sure to put a space after a #

we can also add bullet point- type marks inour r markdown file.

  • one item
  • one item
  • one item
    • one more item
    • one more item
      • one last item

indentation matters and always remember to add the spaces

  1. first item
  2. second item
  1. sub item
  2. sub item

Bloock quotes

we can put really nice quotes into the markdown document. we do this by using “>” symbol.

” genes are like the story and DNA is the lenguage the story is written in”

— Sam Kean

Formulas

we can also put nice formated formulas with two $

hard-weinberg formula

\[p^2 + 2pq + q^2 = 1\]

and you can get really complex

\[\theta = \begin{pmatrix}\alpha & \beta\\ \gamma & \delta \end{pmatrix}\]

code chunks

code chunk options

print("hello world")

there are also options for your R markdown on how knitr interprets the code chunk. there are the following options.

Eval=(t o f): wether or not evaluate the code chunk.

echo=(T O F) wether or not showing the code, but the results will still print.

cache: if enable cache the same code will not be evaluated the next time that the knitr is run. this is great when the code has long run times. if you change something above the value is not going to change.

fig.width ot fig.height: the (graphical device) size of R plots in inches. the figures are first written to knitr document then to file that are saved separately. only changes the sixe of the ones saved externally.

out.width or out.heigth: this one changes the size of the file in the HTML document

fig.cap: the words for the figure caption

table content

we can also add a table of content to our HTML file. we do this by altering the YAML code(the weird code chunk at the very top of the document.)

title: “html” author: “gerard” date: “22/4/2022” output: html_document: toc: true toc_float: true this will gave us a very nice floating table of content.

tabs

ypou can also add tabs in our report. to do this you need to specifyeach section that you want to becomea tab by pleacing {.tabset} after the line. every subsequent header will become a new tab.

themes

you can alsso add themes to your document that will change the headers and hyperlink color of the HTML document. this can be stetically nice. to do this you need to change the YAML to one of the following:

cerulean journal flatly readable spacelab united cosmo lumen paper sandstane simplex yeti null

you can also change the color by specifying highlight:

default tango payments kate monochrome espresso zenburn haddock textmate

code folding

you can also use the code folding to allowed the reader to toggle between displaying the code and hiding the code. this is done with:

code_foolding: hide

summary

ther is a tone of options and ways for you to customize your R code using the HTML format. this is also great way to display a “a portfolio” of your work if you are trying to market yourself to interested parties.

.