Using RStudio

Week 1 In-class Collaboration

This in-class exercise is intended to develop familiarity with the RStudio interface and some useful functions in R.

1 Instructions

You’ll work in groups. Choose one person to share screen within your group, and walk through the instructions below.

To prepare, do the following:

  1. If you haven’t already downloaded the ZIP file for this class, then go ahead and do so.
  2. Open the Project file week1.Rproj from within RStudio.
  3. Once everything loads, use the File tab (in the lower right of RStudio) to click on week1-demo.R to bring the script to the editing window (in the upper left). This is the script we just talked through in the live session.

2 Work through these in your group

  1. Use control-A (command-A on a mac) to highlight the whole script.
  2. Use control-enter to run it (or click the Run button at the top of the file window).
  3. Use the data browser (i.e., from the Environment tab in the upper right) to view the courses dataframe and briefly discuss what you see there.
  4. Now highlight just lines 1-56 and run those. What happened?
  5. In the Console window (bottom left of RStudio), type courses at the command prompt and then hit Enter and discuss what happens.
  6. Type summary(courses) in the command prompt and discuss
  7. Type names(courses) in the command prompt and discuss
Tip

Use of the command prompt

The command prompt in the Console is only used for quick inspection of data, and items 5-7 above are are three common ways to do that.

  1. Create a new R script using the File/New File menu item.
  2. Copy and paste lines 1-56 from week1-demo.R into the new script.
  3. Save it as group_work.R in your Week 1 folder. Notice that it appears in the file browser (in the Files tab in the bottom right).
  4. Close the script by clicking the x on the script tab (in the top of the upper left tab in RStudio), and then re-open it using the lower right Files listing.
  5. Use the project browser (far top right of the window) to close the project, and then re-open it. The drop-down there allows you to quickly switch between projects.