Assignment
Preparing your R Markdown file
In RStudio, choose File > New File > R Markdown…
Delete all the example text in the file. Then copy the chunk below and paste it into your R Markdown file:
---
title: "Data Analytics I: R Assignment"
author: 12345
date: "YYYY-MM-DD"
output: pdf_document
df_print: paged
geometry: margin=2cm ---
Instead of 12345, write your SSE registration number, and instead of YYYY-MM-DD, write today’s date (keep the quotation marks).
Choose File > Save as… and save your file in a folder that you can easily find on your computer.
Knit your file. Knitting means that you let RStudio transform your code into a PDF file. You can find a Knit button in the menu above your code, or you can go to File > Knit Document. (Knitting will take a few moments, so please wait a bit for it to produce the PDF file.) If you encounter problems with knitting your file, you probably have not installed LaTeX properly, so please go back to the installation chapter. When the knitting works you can go to the next step.
Copy the chunk below and paste it below your header. This chunk calls the necessary libraries that you have already installed.
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE) # Show/Hide chunks in output
knitr::opts_chunk$set(message = FALSE) # Show/Hide error messages
knitr::opts_chunk$set(comment = NA) # Show/Hide comments
library(readxl) # For loading Excel files
library(ggplot2) # For graphs
library(tinytex) # For making a pdf
library(tibble) # For the temporary data
library(dplyr)
library(tidyr)
library(RColorBrewer) # For heat map
options(scipen=999) # Fix y-axis formats (for R in general) ```
You should check that your packages have been installed properly. You can do this by pressing the Run button (a green “Play” button) in the top right corner of the chunk.
Transform the initials of your name into two numbers by their order in the alphabet, 1 for A, 2 for B, 3 for C, etc. For example, if your name is Jane Doe, your two numbers would be 10 and 4. Then, replace the constants 10 and 4 in the function f(x)=10√x−4ex with your two numbers and plot the function.
Your chunk should look like this (except for the two constants):
```{r}
f<-function(x){10*sqrt(x)-4*exp(x)}
curve(f) ```
Lastly, choose File > Knit Document. Wait a little, while the program produces your PDF-file. The final PDF-document should be one single page and show a formatted header, your name, today’s date and the plot. E-mail the PDF-document to asser.koskinen@hhs.se for review.
Need more help? Please visit our video channel on Kaltura/SSE Play.