Lab 02: Exercises for the Intro to R Lab

Practicing with R and subsetting

Justin Dainer-Best true
09-07-2020

For each lab, you should expect to download the lab’s files locally to your computer, and run them there. If you’re using https://rstudio.cloud/ instead of running things locally, the same instructions should work today.

These instructions are also on the course github page.

Previous labs

Find the full list of labs here.

Below are instructions for Lab 2.

Make sure you’re in the right working directory

In the first lab, we set the working directory to a specific folder where every lab for this class will live. If you don’t remember, look at the wiki page I’ve created on setting a working directory.

Check that you’re in the directory you expect by running getwd() (the parentheses should have nothing in them). Just copy and paste that into the console and hit return/enter.

Today’s lab

Today’s lab mostly focuses on completing the first tutorial—followed by an exercise.

If you haven’t already downloaded the relevant packages and the tutorial, do so in Lab 1.

If you haven’t already completed the tutorial, you can open it up by pasting the following line to run in your RStudio console, which will open the tutorial.


rmarkdown::run("lab01/intro-to-r.Rmd")

Once you’ve completed the tutorial, return here for an exercise that you will turn in at the end of the lab. Make sure that you close the tutorial window.

Exercise

This exercise gives you the opportunity to do the following:

  1. Practice selecting subsets of data.
  2. Understand how to load a package.
  3. Practice writing your own code in an R Markdown document.

You can download the lab exercise like this:

Run this code in the RStudio console to download the exercise directly into your working directory


usethis::use_zip("https://github.com/jdbest/psy-203/raw/master/lab02.zip", cleanup = TRUE)

After running this, a folder should open with the exercise. You can double click on the file called intro-to-r-exercises.Rmd to open it in RStudio. (If you’d prefer, you should be able to find it in the Files pane: open the folder “lab02” and click on the name of the exercise.)

Solutions

A version of the document with solutions is uploaded to the course website at the end of each week. Once you have filled out the exercise to your own satisfaction, view the “solutions” here.

Citation

For attribution, please cite this work as

Dainer-Best (2020, Sept. 7). PSY 203: Statistics for Psychology: Lab 02: Exercises for the Intro to R Lab. Retrieved from https://faculty.bard.edu/jdainerbest/psy-203/posts/2020-09-07-lab-2-exercises-for-the-intro-to-r/

BibTeX citation

@misc{dainer-best2020lab,
  author = {Dainer-Best, Justin},
  title = {PSY 203: Statistics for Psychology: Lab 02: Exercises for the Intro to R Lab},
  url = {https://faculty.bard.edu/jdainerbest/psy-203/posts/2020-09-07-lab-2-exercises-for-the-intro-to-r/},
  year = {2020}
}