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.
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:
Open RStudio
Create a new R script by going to
File -> New File -> R Script or pressing
Ctrl/Cmd+Shift+N
Save your script as lastname_lab_week_1.R in an
appropriate location (with your own last name)
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
Use parentheses to edit 15 + 7 * 3 force R to return
66 instead of 36.
Calculate the square root of 144.
Calculate 2 raised to the power of 8.
Part 2: Objects and Assignment
Create an object called current_year and assign a
value of 2025 to it using the <-
operator.
Calculate how many years it has been since 1977
using the current_year object.
Part 3: Mathematical Functions
Calculate the natural logarithm of 10 using the
log() function.
Calculate e raised to the power of 2 using the exp()
function.
Part 4: Logical Comparisons
Test whether 10 is equal to 5 + 5 using the ==
operator.
Test whether 7 is greater than 10.
Test whether 15 is greater than or equal to 15.
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
Use the help function to learn about the round()
function by typing ?round in the console.
Round the number 3.14159 to 2 decimal places using the
round() function.
Calculate the absolute value of -15 using the abs()
function.
Part 6: Working with Scripts
Add comments to your script using # to explain what
each section does.
Save your script and make sure you can run the entire script from top to bottom without errors.
# 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.
In this lab we are going to practice subsetting and manipulating vectors.
Lab this week will be playing with the surveys data we
worked on in class.
This week the lab will review data manipulation in the tidyverse, using the international environmental agreements data from lecture.
This week’s questions will have us practicing pivots, conditional statements, and joins with the international environmental agreements data.
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.
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.
Functions lab — placeholder; content to be added.
This lab is being updated — check back soon.
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.