Pre-work

Welcome to ID 543! Before we get started, there are a few things you need to do to prepare. Please work through the following information before class begins, and come to office hours if you have any questions or run into any issues.

Video

To help you get started, I recorded a video that walks you through the basics of R and RStudio, including how to install packages, how to run code, and how to use the RStudio interface. You’ll want to familiarize yourself with this information before doing the reading below.

The video goes over some slides, which you can open in a new tab here or follow along below the video (use your arrow keys to switch slides).

(P.S. Sorry, I didn’t realize the video of my face would be in the screen instead of off to the side!)

Install R and RStudio

  1. Download R from CRAN. Choose the link at the top that corresponds to your operating system. Unless you downloaded R within the past few months, do so again – you want the most up-to-date version for this class (must be at least 4.2).

  2. Download RStudio (step 2 on that page – you already completed step 1 above!). It should automatically recognize your operating system, but if not, choose the correct link at the bottom.

  3. You’ll also need to install some packages before class. You’ll go through that process in the reading below, but please make sure to do so before class (it can take a little while).

If you have a Mac, make sure you choose correctly between the Apple Silicon and Intel options.Again, make sure you have a relatively recent version (≥ 2022.07.01), but the newest versions have the most helpful features.

Readings

  1. Introduction: Prerequisites of R for Data Science. Run the code in your RStudio console as you go.

  2. Chapter 2: Workflow: basics of R for Data Science. Again, run the code in your RStudio console as you read. Try the exercises.

  3. Optional, but helpful: Chapter 2 of Hands-On Programming with R. For the purposes of this class, we will necessarily skip some of the R basics to focus on the skills you’ll need most. This is a good resource if you want to learn more about them, so it’s highly recommended, you just don’t need to master it as part of your pre-work.

In particular, make sure you install the packages in the text.If you’re wondering what happened to chapter 1, we’ll be doing that one together!

Exercises

Try these exercises to familiarize yourself with R and RStudio. You’ll render the document and turn in the html file as shown in the video, but it will be graded for effort rather than correct responses. We’ll go through it together at the beginning of class!

To do so, download this quarto file and open it in RStudio. You can open RStudio and find the file where you’ve saved it with File->Open File, or RStudio should open automatically if you double-click the .qmd file (if this doesn’t happen, change the filetype association on your Windows or Mac). Edit and add to the code in this document to answer these questions:

  1. Run this R code (1 line at a time). For each line, note the error message and fix the code so it runs without errors:
# Fix this:
3ages <- c(20, 21, 19)

# Fix this:
heights <- (163, 180, 148)

# Fix this:
fruits <- c(apple, banana, cherry)

# Fix this:
my colors <- c("red", "blue", "green")

# Fix this so that the value is stored as mean_val:
mean(c(10, 15, 20))
  1. Create a new vector called heights with these values: 165, 172, 158, 180, 177, 169. Look in your environment. What happened to your heights object from the previous question?
  2. Use the following functions on your new heights vector and store each result:
    • min(): store as shortest
    • max(): store as tallest
    • median(): store as median_height
    • length(): store as num_people
  3. Create a new vector called heights_inches that converts the heights to inches (1 inch = 2.54 cm).

Resources