--- title: "Intro to Rmarkdown and home exercises" author: "Your Name" date: "4.8.2023" --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ### R Markdown This is an R Markdown document. Open the .Rmd version of it in Rstudio. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . When you click the **Knit** button in Rstudio icon bar a html/pdf/word document will be generated that includes both the 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} x = 1:5 sqrt(x) #compute square root of 1,2,...5. ``` You can choose the output format (html/pdf/word) from the downward arrow on the right hand side of the `Knit` button. If your `Knit` button doesn't have the PDF option available, you should follow the instructions at to install the `tinytex` package. Namely, run in the R console the following commands (which are not run automatically here because we have set `eval = FALSE` in the R code block below) ```{r, eval = FALSE} install.packages('tinytex',repos = "https://cloud.r-project.org") tinytex::install_tinytex() # to uninstall TinyTeX, run tinytex::uninstall_tinytex() ``` Home exercises are given in Rmd files (also PDF is given). You can do the exercises using R markdown by directly writing your answers below each question (remember to use R chunk for code in order that Rstudio knows to interpret it as code and run it in R). Return your solutions as a PDF or HTML file by saving from R markdown (option arrow on the right hand side of **Knit** button). If you `Knit` to a Word file, then save the result in Word as PDF before returning the document. Note that your solutions must contain both the R code and the output from R when the code was run, including the plots that were asked to be drawn. If you are not able to get Rstudio to `Knit` Rmarkdown file, you can write your solution code in a new R script file (Choose File -> New File -> R script). Then you should run the commands on the console and copy the relevant output to your solution file (also figures), which may be a text file of any type (such as MS Word), and save the final document as PDF. But this is not the recommended option because copy-paste is complicated and error prone, and you won't learn to use Rmarkdown for your future projects. #### Toy set of exercises Write your name at the beginning of this file as "author:". Write your answers below each question using chunks for R commands. After every step, you can `Knit` to HTML and see that everything looks good. Once you are ready with everything, try to create a PDF and check that also it looks good. Solutions to 2 & 3 are given at the bottom of this document. (1) Assign value 2 to variable `x` and compute `x + 3`. ```{r} #Your answer goes here x = 2 x + 3 ``` (2) Suppose that we have checked the month of birth for $N = 5000$ MS-disease patients and observed that $A = 485$ of them were born in April. Compute how large proportion of the patients were born in April. (A code block is made ready for you below, just put there your R commands.) ```{r} #Your answer goes here ``` (3) Compute the mean and the standard deviation of the following 5 values: 4, 92, 11, -5, -12. (Start by making a code block for your R commands, for example, by copying a block from above or by choosing **R** from `+C` button in the bar above this editor.) #### Answers 2-3. Answer (2). ```{r} N = 5000 A = 485 A / N ``` Answer (3). ```{r} x = c(4, 92, 11, -5, -12) mean(x) sd(x) ```