Labs are designed to reinforce the code/lessons covered that week and provide you a chance to practice working with R. Labs are to be completed in your local project (on your computer) and uploaded to Canvas by the beginning of class (1pm) the following Thursday. That said, these due dates are largely suggestive as a way to help you prioritize and stay caught up as a group – if you need, or want, more time, take it. At the end of the quarter, we will simply look over the tasks you have completed in concert with the reflection you submit.


Labs

Lab Week 1

This lab will help you get oriented with R, RStudio, and your first programming concepts. The goal is to practice the fundamentals covered in the the introduction to R and RStudio lecture.

Setup Instructions:

  1. Open RStudio

  2. Create a new R script by going to File -> New File -> R Script or pressing Ctrl/Cmd+Shift+N

  3. Save your script as lastname_lab_week_1.R in an appropriate location (with your own last name)

  4. As you work through the problems below, write your code in the script and run it using Ctrl/Cmd+Enter (try to practice not highlighting and clicking “run”)

Part 1: Basic Arithmetic and Order of Operations

  1. Use parentheses to edit 15 + 7 * 3 force R to return 66 instead of 36.

  2. Calculate the square root of 144.

  3. Calculate 2 raised to the power of 8.

Part 2: Objects and Assignment

  1. Create an object called current_year and assign a value of 2025 to it using the <- operator.

  2. Calculate how many years it has been since 1977 using the current_year object.

Part 3: Mathematical Functions

  1. Calculate the natural logarithm of 10 using the log() function.

  2. Calculate e raised to the power of 2 using the exp() function.

Part 4: Logical Comparisons

  1. Test whether 10 is equal to 5 + 5 using the == operator.

  2. Test whether 7 is greater than 10.

  3. Test whether 15 is greater than or equal to 15.

  4. Create an object called x with the value 25, then test whether x is not equal to 30.

Part 5: Exploring Functions and Getting Help

  1. Use the help function to learn about the round() function by typing ?round in the console.

  2. Round the number 3.14159 to 2 decimal places using the round() function.

  3. Calculate the absolute value of -15 using the abs() function.

Part 6: Working with Scripts

  1. Add comments to your script using # to explain what each section does.

  2. Save your script and make sure you can run the entire script from top to bottom without errors.

ANSWER
# Part 1
(15 + 7) * 3       # 1. parentheses force 66
sqrt(144)          # 2. -> 12
2^8                # 3. -> 256

# Part 2
current_year <- 2025
current_year - 1977  # 5. -> 48

# Part 3
log(10)            # 6. natural log
exp(2)             # 7. e^2

# Part 4
10 == 5 + 5        # 8.  TRUE
7 > 10             # 9.  FALSE
15 >= 15           # 10. TRUE
x <- 25
x != 30            # 11. TRUE

# Part 5
?round             # 12. opens help
round(3.14159, 2)  # 13. -> 3.14
abs(-15)           # 14. -> 15

# Part 6: 15-16 are commenting (#) and running the whole script top to bottom.

Lab Week 2

In this lab we are going to practice subsetting and manipulating vectors.

Download Lab 2 (.qmd)

Lab Week 3

Lab this week will be playing with the surveys data we worked on in class.

Download Lab 3 (.qmd)

Lab Week 4

This week the lab will review data manipulation in the tidyverse, using the international environmental agreements data from lecture.

Download Lab 4 (.qmd)

Lab Week 5

This week’s questions will have us practicing pivots, conditional statements, and joins with the international environmental agreements data.

Download Lab 5 (.qmd)

Lab Week 7

For our week seven lab, we are going to be practicing the skills we learned with ggplot during class. You will be happy to know that we are going to be using a brand new data set called gapminder.

Download Lab 7 (.qmd)

Lab Week 8

For our week eight lab, we are going to practice making plots that you could show to someone else. First we’ll fix up a messy plot of the environmental impact statement (EIS) data from lecture, and then you’ll make a plot of your own with some new data.

Download Lab 8 (.qmd)

Lab Week 9

Functions lab — placeholder; content to be added.

This lab is being updated — check back soon.

Lab Week 10

In this assignment, you’ll use the iteration skills we built in the course to apply functions to an entire dataset.

This lab is being updated — check back soon.