Problem set 1

Due by 11:59 PM on Monday, February 11, 2019

Note: to complete this task, you MUST submit your final folder (compressed as a zip file) through here to Canvas by 11:59pm on February 11, 2018. Each person needs to submit their own folder! So if you work in pairs, both individuals have to submit a folder.

Task 0

Create a new R project as a “New Directory” (folder).

Within your new project folder, download this R Markdown file.Your browser might show the file instead of downloading it. If that’s the case, you can copy/paste the code from the browser to RStudio. In RStudio, go to “File” > “New” > “New R Markdown…”, click “OK” with the default options, delete all the placeholder code/text in the new file, and paste the example code in the now-blank file.

It contains an outline/skeleton of what you’ll need to do in this problem set, and it includes lots of the code prewritten just for you!

Make sure you install R and RStudio and tidyverse first.Follow these instructions and install R, RStudio, and all the tidyverse packages. If you have any questions, don’t hesitate to ask me or your classmates for help!

Complete the three tasks below and type your answers in that downloaded file. When you’re done, knit the document as a html file with the “Knit” button at the top of the script editing pane.Knit button

Task 1: Become familiar with RStudio and R Markdown

In Task 2, you’ll play with actual R commands and create graphics. Before we get there, you need to familiarize yourself with RStudio. Go through this short tutorial.

Finally, you will write future memos and problems sets in R Markdown instead of Word. RStudio has a helpful tutorial and a short video about R Markdown. Go through these short lessons:

Before doing these R Markdown tutorials, you’ll need to install a couple more R packages. Use RStudio’s “Packages” panel to install rmarkdown and viridis. Alternatively, paste these commands in the RStudio Console: install.packages("rmarkdown") and install.packages("viridis"). You can also type install.packages(c("rmarkdown", "viridis")) to install both at the same time.

Don’t worry if you don’t completely understand R Markdown!See R4DS Chapter 27 if you need some help.

Try your hardest and play around with it.

Also, (optional) if you want to convert R Markdown files to PDF instead of just Word or HTML, you’ll need to install LaTeX, which is a fancy scientific typesetting program. You don’t need to know how it works—it just has to be installed for R to use it.

The easiest way to install it is with the tinytex R package. Run these two lines in your R console to install a smaller version of LaTeX that should work great for this class:

If you want to use a full-blown LaTeX installation, install one of these. But note that you don’t need to do this!

When you’re done with everything in Task 1, type something in the R Markdown skeleton file you downloaded at the beginning. You should see a # Task 1 heading. Type it under that.

Task 2: Playing with R

This example uses data from the Gapminder project. You may have seen Hans Rosling’s delightful TED talk showing how global health and wealth have been increasing. If you haven’t, you should watch it. Sadly, Hans died in February 2017.

You’ll need to install the gapminder R package first. Install it either with the “Packages” panel in RStudio or by typing install.packages("gapminder") in the R console.

For this task, you won’t do any actual coding. The skeleton R Markdown file has all the code you need for this task. Download it, open it in RStudio, and walk through the examples in RStudio on your computer. If you place your cursor on some R code and press “⌘ + enter” (for macOS users) or “ctrl + enter” (for Windows users), RStudio will send that line to the console and run it.

There are a few questions that you’ll need to answer, but that’s all. Those are marked with “TYPE YOUR ANSWER HERE.”

Task 3: R and ggplot2

Read Chapter 3 of R for Data Science and complete the following exercises:

All done!

Knit the completed R Markdown file as a html (use the “Knit” button at the top of the script editor window) and compress the entire folder (including the html document, RStudio Project, any respective data, and the R Markdown file). To complete the assignment, upload here to Canvas by 11:59pm on February 11, 2018. Each person needs to submit their own folder. (Example: if you work with someone else, you both have to submit a folder!)